user1450760
user1450760

Reputation: 21

Facebook scores api with iOS5.1 - Can read scores... but cant post them

I'm new to iOS development, I have successfully integrated facebook login and such... however my problem is with the Score api. i can read the score but i cant seem to post it, i have the publish_actions permission and also am getting back a valid access_token.Not sure what the problem it, here is my code -

NSString *accessTokenToUse = [NSString stringWithFormat:@"%@",[self.facebook accessToken] ];

    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                   //@"233", @"score",
                                   accessTokenToUse, @"access_token",
                                   nil];
    NSMutableDictionary *paramsB = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                   @"233", @"score",
                                   accessTokenToUse, @"access_token",
                                   nil];
    NSLog(@"APP ACCESS TOKEN: %@",accessTokenToUse);

    [self.facebook requestWithGraphPath:@"me/scores" andParams:paramsB andHttpMethod:@"POST" andDelegate:self];
    [self.facebook requestWithGraphPath:@"APP_ID/scores" andParams:params andHttpMethod:@"GET" andDelegate:self];

***EDIT - Still doesn't work

NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                               @"233", @"score", 
                               @"[APP_ACCESS_TOKEN (omitted for stackoverflow)]", @"access_token", nil];
[self.facebook requestWithGraphPath:@"/[userID]/scores" andParams:params andHttpMethod:@"POST" andDelegate:self];

EDIT - SOLVED

So bascially i WAS passing in the correct token, however the facebook sdk was overwriting it in Facebook.m to the user's access token. So the fix was simple - whenever i need to pass in the App's token i just add an other parameter < key=@"useAppToken" Value=@"yes" > and in Facebook.m just add an if statement within isSessionValid -

- (FBRequest*)openUrl:(NSString *)url
           params:(NSMutableDictionary *)params
       httpMethod:(NSString *)httpMethod
         delegate:(id<FBRequestDelegate>)delegate {

NSLog(@"PARAMS BFORE: %@ ", params);
[params setValue:@"json" forKey:@"format"];
[params setValue:kSDK forKey:@"sdk"];
[params setValue:kSDKVersion forKey:@"sdk_version"];

if ([self isSessionValid]) {
    if ([params objectForKey:@"useAppToken"] == nil || [params objectForKey:@"useAppToken"] == @"no") {
        [params setValue:self.accessToken forKey:@"access_token"];
    }

}
NSLog(@"PARAMS AFTER: %@ ", params);
[self extendAccessTokenIfNeeded];

FBRequest* _request = [FBRequest getRequestWithParams:params
                                           httpMethod:httpMethod
                                             delegate:delegate
                                           requestURL:url];
[_requests addObject:_request];
[_request addObserver:self forKeyPath:requestFinishedKeyPath options:0    context:finishedContext];
[_request connect];
return _request;

}

Be sure to comment out the NSLogs in this... :)

Upvotes: 2

Views: 1233

Answers (2)

Goli
Goli

Reputation: 67

Looks like it's a bug: http://developers.facebook.com/bugs/461900043821056

But if you change your app settings to web app instead of native it would work.

Upvotes: 0

Juicy Scripter
Juicy Scripter

Reputation: 25928

Scores can only be published using application access_token and not one for user (which you probably using, it's ok for reading the scores but don't allow you to publish 'em).

Citing the Scores documentaion:

Create or update a score for a user
You can post a score or a user by issuing an HTTP POST request to /USER_ID/scores with the app access_token as long as you have the publish_actions permission.

Upvotes: 1

Related Questions