2

我正在尝试在我的应用程序中使用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的完成处理程序中。

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

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;

为什么我会收到此错误?

4

0 回答 0