Question

I have an option in my game for users to post an achievement to their wall. If they are logged in, i.e. their token is still active, it works fine. However, if they need to renew their token, the app exits and the Facebook authentication page loads for a second before returning to the app (they only need to click OK on the authentication page if they have actively logged out, otherwise it happens automatically).

The problem is that if this happens, when the game returns, the request fails. But since they're now logged in, if they were to press the 'share to wall' button a second time, it works fine. The error message output by the failed request it:

    DIDLOGIN
2012-02-21 12:01:33.502[18153:15803] Response received
2012-02-21 12:01:33.502[18153:15803] Request did load raw response
2012-02-21 12:01:33.502[18153:15803] Request failed, error: Error Domain=facebookErrDomain Code=10000 "The operation couldn’t be completed. (facebookErrDomain error 10000.)" UserInfo=0x9992010 {error=<CFBasicHash 0x99785e0 [0x2093b38]>{type = mutable dict, count = 3,
entries =>
    2 : <CFString 0x9963370 [0x2093b38]>{contents = "type"} = <CFString 0x99952a0 [0x2093b38]>{contents = "OAuthException"}
    3 : <CFString 0x99631e0 [0x2093b38]>{contents = "message"} = <CFString 0x997e5b0 [0x2093b38]>{contents = "An active access token must be used to query information about the current user."}
    6 : <CFString 0x998c370 [0x2093b38]>{contents = "code"} = 2500
}
}

I'm not sure why I'm getting an OAuthException when I've just successfully authorised it?

Thanks for any help!

Was it helpful?

Solution 2

Well, I found the problem. At least I think I found it, as it now works, I just hope I didn't introduce another error in the process. Basically my login coded looked like this:

    - (void)postAchievement:(NSString *)message withPicture:(NSString *)pictureURL {
    //Set post to TRUE so the delegate posts when the method returns and configure the message. 
    DLog(@"Achievement message: %@", message);
    self.postAchievement = TRUE;
    self.achievementMessage = message;
    self.wallPostPicURL = pictureURL;
    [self fbLogin];
[facebook requestWithGraphPath:@"me" andDelegate:self];
}

    // Save the user's credentials and expiration date
- (void)fbDidLogin {
    DLog(@"DIDLOGIN");
    self.isLoggedIn = TRUE;
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    [defaults setObject:[facebook accessToken] forKey:@"FBAccessTokenKey"];
    [defaults setObject:[facebook expirationDate] forKey:@"FBExpirationDateKey"];
    [defaults synchronize];
}

fbDidLogin is a delegate method called when the user has logged in. The line [facebook requestWithGraphPath:@"me" andDelegate:self]; was the problem. I moved it to the end of the fbDidLogin method and now it seems to work perfectly.

OTHER TIPS

when you set the dictionary of params that you send it to the facebook .. pass the acces token also ,, like this

    NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                               @"someText",  
                               @"message",
                               [fb accessToken], 
                               @"access_token",nil];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top