I am trying to use the Three20 Facebook sample app along with the Facebook Graph API (to authenticate and get an access token). I am using the following code for the TTURLRequest:
- (void)load:(TTURLRequestCachePolicy)cachePolicy more:(BOOL)more {
if (!self.isLoading && TTIsStringWithAnyText(_query)) {
NSString* url = _query;
NSLog(@"load:%@:", url);
TTURLRequest* request = [TTURLRequest requestWithURL:url delegate:self];
request.cachePolicy = cachePolicy | TTURLRequestCachePolicyEtag;
request.cacheExpirationAge = TT_CACHE_EXPIRATION_AGE_NEVER;
TTURLJSONResponse* response = [[TTURLJSONResponse alloc] init];
request.response = response;
TT_RELEASE_SAFELY(response);
[request send];
}
}
This works perfectly for urls without access tokens (i.e. https://graph.facebook.com/markzuckerberg/feed) but whenever I use an access token on the exact same page (i.e. https://graph.facebook.com/markzuckerberg/feed?access_token=...) I get an error with the description "bad url." Copying either URL into a web brow开发者_如何学编程ser shows that both work fine, but the URL Request only generates an error for the one with the access_token.
The only possible explanation I could think of is that TTURLRequest has a limit on the length of the URL. Does anyone have any idea why this might be happening and/or have any workarounds?
Update: This is how I construct the URL:
self.accessToken = [_facebook.accessToken stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
self.dataSource = [[[TTFacebookNewsFeedDataSource alloc] initWithQuery:[NSString stringWithFormat:@"http://graph.facebook.com/markzuckerberg/feed?access_token=%@", self.accessToken]] autorelease];
I fixed this issue by using FBRequest serializeURL:
AppDelegate *appDel = (AppDelegate *)[[UIApplication sharedApplication] delegate];
NSString* url = [FBRequest serializeURL:@"https://graph.facebook.com/me/home" params:[NSMutableDictionary dictionaryWithObject:appDel.facebook.accessToken forKey:@"access_token"]];
Check the syntax of your url. I assume you did not properly escape your get parameters, e.g. the access token and/or other parameters.
精彩评论