Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facebook Access Token Expired - iOS 6 Social Framework

I'm making an app based on iOS6 Social Framework...it was working fine but now after few months got an weird error.

My NSLog of imported JSON Facebook data to a NSDictionary is:

profiledictionary: {
error = {
code = 190;
"error_subcode" = 463;
message = "Error validating access token: Session has expired at unix time 1365610034. The current unix time is 1366032783.";
type = OAuthException;

Seems my access token has expired, but isn't iOS6 Social Framework supposed to take care of it automatically?

Any ideas about how can I solve it and also avoid future problems like that, so I can safe publish a real app?

like image 687
Marcos Reboucas Avatar asked Apr 15 '13 21:04

Marcos Reboucas


1 Answers

finally got it...was necessary to check if NSDictionary had an object named "error" (in this case Facebook error about token expired), and if so call a method to renew ACAccount:

if([self.profileDictionary objectForKey:@"error"]!=nil)
{
[self attemptRenewCredentials]; 
}

-(void)attemptRenewCredentials{
    [self.accountStore renewCredentialsForAccount:(ACAccount *)self.facebookAccount completion:^(ACAccountCredentialRenewResult renewResult, NSError *error){
        if(!error)
        {
            switch (renewResult) {
                case ACAccountCredentialRenewResultRenewed:
                    NSLog(@"Good to go");
                    [self getFacebookAccount];
                    break;
                case ACAccountCredentialRenewResultRejected:
                    NSLog(@"User declined permission");
                    break;
                case ACAccountCredentialRenewResultFailed:
                    NSLog(@"non-user-initiated cancel, you may attempt to retry");
                    break;
                default:
                    break;
            }

        }
        else{
            //handle error
            NSLog(@"error from renew credentials%@",error);
        }
    }];
}
like image 107
Marcos Reboucas Avatar answered Sep 23 '22 22:09

Marcos Reboucas