Skip to content

Commit

Permalink
Correct format string for optional parameters
Browse files Browse the repository at this point in the history
Fixes #34
If the request already contains optional parameters, the format string is slightly different for GET
requests as the access_token is no longer the only parameter.
  • Loading branch information
philippec committed Jan 3, 2012
1 parent f046f72 commit 732b729
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
11 changes: 10 additions & 1 deletion classes/PhFacebook.m
Expand Up @@ -181,9 +181,18 @@ - (void) sendFacebookRequest: (NSDictionary*) allParams
BOOL postRequest = [[allParams objectForKey: @"postRequest"] boolValue]; BOOL postRequest = [[allParams objectForKey: @"postRequest"] boolValue];


if (postRequest) if (postRequest)
{
str = [NSString stringWithFormat: kFBGraphApiPostURL, request]; str = [NSString stringWithFormat: kFBGraphApiPostURL, request];
}
else else
str = [NSString stringWithFormat: kFBGraphApiGetURL, request, _authToken.authenticationToken]; {
// Check if request already has optional parameters
NSString *formatStr = kFBGraphApiGetURL;
NSRange rng = [request rangeOfString:@"?"];
if (rng.length > 0)
formatStr = kFBGraphApiGetURLWithParams;
str = [NSString stringWithFormat: formatStr, request, _authToken.authenticationToken];
}




NSDictionary *params = [allParams objectForKey: @"params"]; NSDictionary *params = [allParams objectForKey: @"params"];
Expand Down
1 change: 1 addition & 0 deletions private/PhFacebook_URLs.h
Expand Up @@ -22,6 +22,7 @@
#define kFBErrorReason @"error_description=" #define kFBErrorReason @"error_description="


#define kFBGraphApiGetURL @"https://graph.facebook.com/%@?access_token=%@" #define kFBGraphApiGetURL @"https://graph.facebook.com/%@?access_token=%@"
#define kFBGraphApiGetURLWithParams @"https://graph.facebook.com/%@&access_token=%@"


#define kFBGraphApiPostURL @"https://graph.facebook.com/%@" #define kFBGraphApiPostURL @"https://graph.facebook.com/%@"


Expand Down

0 comments on commit 732b729

Please sign in to comment.