FBSession验证访问令牌时出错:会话与当前存储的会话不匹配

时间:2014-08-30 17:14:23

标签: ios objective-c salesforce facebook-sdk-3.1 salesforce-ios-sdk

我正在尝试在我的应用程序中使用 Facebook SDK 。我的应用程序使用Salesforce SDK来记录Salesforce,用户可以使用Facebook登录我的应用程序。

当用户使用Facebook登录时,Salesforce可以使用Facebook访问令牌。我使用此访问令牌打开对象 FBSession

的会话

这是我用来打开会话的代码:

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) {

}];

我正在尝试发布链接并获取我的朋友列表。

要发布我使用此代码:

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) 这只有在我使用

关闭并再次打开我的应用程序时才有效
[FBSession.activeSession closeAndClearTokenInformation];

在openFromAccessTokenData的 completionHandler 中。

有没有办法让这项工作无需关闭并重新打开我的应用程序?

2) 当我尝试使用此代码获取我的朋友列表时:

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

我收到此错误:

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;

为什么我会收到此错误?

0 个答案:

没有答案