FBSession Error validating access token: Session does not match current stored session

473 Views Asked by At

I'm trying to use Facebook SDK in my application. My application is using Salesforce SDK to logging with Salesforce and the user can use Facebook to logging in my application.

From Salesforce can take the Facebook access token when the user logs in with Facebook. I use this access token to open a session with the object FBSession.

This is the code that I'm using to open a session:

NSArray *newPermission = [NSArray arrayWithObjects:@"user_friends",@"email", nil];
NSMutableDictionary *tokenInformationDictionary = [NSMutableDictionary new];
tokenInformationDictionary[@"com.facebook.sdk:TokenInformationExpirationDateKey"] = [NSDate dateWithTimeIntervalSinceNow: 3600];;
tokenInformationDictionary[@"com.facebook.sdk:TokenInformationRefreshDateKey"] = [NSDate date];
tokenInformationDictionary[@"com.facebook.sdk:TokenInformationTokenKey"] = fbAccessToken;
tokenInformationDictionary[@"com.facebook.sdk:TokenInformationPermissionsKey"] = newPermission;
tokenInformationDictionary[@"com.facebook.sdk:TokenInformationLoginTypeLoginKey"] = @0;
FBAccessTokenData *accesToken = [FBAccessTokenData createTokenFromDictionary: tokenInformationDictionary];
        [[FBSession activeSession] openFromAccessTokenData:accesToken completionHandler:^(FBSession *session, FBSessionState status, NSError *error) {

}];

I'm trying to publish links and get my friends list.

To publish I use this code:

NSDictionary *params = @{
    @"name" : [NSString stringWithFormat:NSLocalizedString(@"FBNameFormat", nil), [dicRecord objectForKey:@"Name"], [[dicRecord objectForKey:@"Store__r"] objectForKey:@"Name"]],
                         @"caption" : [NSString stringWithFormat:NSLocalizedString(@"FBCaptionFormat", nil), [dicRecord objectForKey:@"Name"], [[dicRecord objectForKey:@"Store__r"] objectForKey:@"Name"]],
                         @"description" : NSLocalizedString(@"FBDescription", nil), //@"Welcome to iOS world",
                         @"picture" : [dicRecord objectForKey:@"Image__c"],
                         @"link" : [NSString stringWithFormat:NSLocalizedString(@"FBDishUrl", nil), [dicRecord objectForKey:@"Id"]]//a00w000000V0TK9",
                         };

// Invoke the dialog
[FBWebDialogs presentFeedDialogModallyWithSession:nil  parameters:params handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {

    if (error) {
        NSLog(@"Error publishing story.");
        //[self.indicator stopAnimating];
    } else if (result == FBWebDialogResultDialogCompleted){
        if ([isSuggested isEqual:[NSNumber numberWithInt:-1]]){
            NSMutableDictionary *diccionario = [[NSMutableDictionary alloc] init];

        }
    }
}];

1) That only works if I close and open again my apps, using

[FBSession.activeSession closeAndClearTokenInformation];

in completionHandler of openFromAccessTokenData.

Is there a way to make this work without having to close and re-open my app?

2) When I try to get my Friend list using this code:

FBRequest *reqMyFriends = [FBRequest requestForMyFriends];
reqMyFriends.session = FBSession.activeSession;
[reqMyFriends startWithCompletionHandler:^(FBRequestConnection *connection, NSDictionary* result,NSError *error) {
    if (!error){
        NSArray* friends = [result objectForKey:@"data"];
    }
}];

I get this error:

error =
{
    code = 190;
    "error_subcode" = 460;
    message = "Error validating access token: Session does not match current stored session. This may be because the user changed the password since the time the session was created or Facebook has changed the session for security reasons.";
     type = OAuthException;
};
code = 400;

Why do I get this error?

0

There are 0 best solutions below