4

After my app gained access to facebook account registered in iOS 6's setting, I revoked the app from my facebook's privacy setting. And then I try to reconnect my app with facebook by calling [FBSession openActiveSessionWithReadPermissions...] and that method create facebook session using old access token, which is INVALID already, without asking permission grant again.

I think this problem has something to do with this question (Facebook SDK 3.1 - Error validating access token) and it is said to be fixed in SDK 3.1.1.

However, I'm using SDK 3.1.1 and working around this problem by calling accountStore renewCredentialsForAccount thing manually whenever invalid access token error occurs.

Community
  • 1
  • 1
minorblend
  • 905
  • 1
  • 10
  • 23
  • 1
    I had the same problem that you are describing here and I have been able to *solve* it (let's better say *bypass* it) using the accepted answer of the [question](http://stackoverflow.com/questions/12601191/facebook-sdk-3-1-error-validating-access-token) that you pointed. Thanks! – hectr May 14 '13 at 07:22

1 Answers1

5

Based on this thread, the only way I found to validate a valid session was to perform a simple graph API call. In case of an error, FBSession.activeSession.isOpen will return NO, which is a good indication that the token has expired.

+ (void) ValidateSession
{    
    FBRequest *userDetails = [[FBRequest alloc] initWithSession:FBSession.activeSession graphPath:@"/me"];
    [userDetails startWithCompletionHandler:^(FBRequestConnection *connection, NSDictionary *result, NSError *error) {

        if (error) {
            if (FBSession.activeSession.isOpen) {
                // Less probable, so check error code.
            } else {
                // Bingo: here we know for sure that the token was useless.
                // Expected behavior: reauthorize.
            }
        } else if (result) {
            NSLog(@"%@", result);
            // token is valid, continue
        }

    }];
}

It seems that iOS keeps Facebook tokens even after an app was deleted, so it's a good practice to reinsure that the token is valid whenever needed.

Community
  • 1
  • 1
Tal Yaniv
  • 493
  • 6
  • 13