Marcos Reboucas
Marcos Reboucas

Reputation: 3489

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?

Upvotes: 9

Views: 1750

Answers (1)

Marcos Reboucas
Marcos Reboucas

Reputation: 3489

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);
        }
    }];
}

Upvotes: 13

Related Questions