升级到适用于 iOS 的 ParseSDK 1.7.5 和 FacebookSDK 4.4.0 后出错

Posted

技术标签:

【中文标题】升级到适用于 iOS 的 ParseSDK 1.7.5 和 FacebookSDK 4.4.0 后出错【英文标题】:Error after upgrading to ParseSDK 1.7.5 and FacebookSDK 4.4.0 for iOS 【发布时间】:2015-08-06 01:24:04 【问题描述】:

当我尝试使用 PFFacebookUtilsV4 将 Parse 用户与 Facebook 链接时,它给了我以下警报:

“请重新登录此应用以重新连接您的 Facebook 帐户”

这是我调用 PFFacebookUtils 的代码块:

/**
 * Import people you are friends with on facebook from the database
 */
- (void)beginImportingFacebookFriendsForUserWithBlock:(void (^)(NSArray *results, NSError *error))cb 

  if (![PFFacebookUtils isLinkedWithUser:[PFUser currentUser]]) 

    NSArray *permissionsArray = @[@"user_about_me", @"user_friends", @"user_events"];
    [PFFacebookUtils linkUserInBackground:[PFUser currentUser] withReadPermissions:permissionsArray block:^(BOOL succeeded, NSError *error) 
      if (succeeded) 
        FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc] initWithGraphpath:@"me"
                                                                       parameters:nil];
        [request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) 
          if (!error) 
            NSString *fbId = [result objectForKey:@"id"];
            NSMutableDictionary *currentUserDict = [[prefs objectForKey:@"currentUser"]mutableCopy];
            NSLog(@"currentUserDict:%@",currentUserDict);
            [currentUserDict setObject:fbId forKey:@"fbId"];
            [prefs setObject:currentUserDict forKey:@"currentUser"];
            [prefs setObject:fbId forKey:@"currentFbId"];
            [[PFUser currentUser] setObject:fbId forKey:@"fbId"];
            [[PFUser currentUser] saveInBackground];

            [self finishImportingFacebookFriendsForUserWithBlock:cb];
          
        ];
      
    ];
  
  else 
    [self finishImportingFacebookFriendsForUserWithBlock:cb];
  


- (void)finishImportingFacebookFriendsForUserWithBlock:(void (^)(NSArray *, NSError *))cb 
  FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc] initWithGraphPath:@"me"
                                                                 parameters:nil];
  [request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) 
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^
      if (!error) 
        NSLog(@"result objectforkey:data %@", [result objectForKey:@"data"]);
        cb([result objectForKey:@"data"], error);
      
      else NSLog(@"error!:%@",error);
    );
  ];

这是我在控制台日志中得到的内容:

2015-08-05 21:18:54.723 Huddlr[2965:391917] error!:Error Domain=com.facebook.sdk.core Code=8 "The operation couldn’t be completed. (com.facebook.sdk.core error 8.)" UserInfo=0x1741aca20 NSRecoveryAttempter=<_FBSDKLoginRecoveryAttempter: 0x174019da0>, NSLocalizedRecoverySuggestion=Please log into this app again to reconnect your Facebook account., com.facebook.sdk:FBSDKGraphRequestErrorGraphErrorCode=190, com.facebook.sdk:FBSDKErrorDeveloperMessageKey=Error validating access token: The session has been invalidated because the user has changed the password., com.facebook.sdk:FBSDKGraphRequestErrorHTTPStatusCodeKey=400, com.facebook.sdk:FBSDKGraphRequestErrorCategoryKey=2, com.facebook.sdk:FBSDKGraphRequestErrorGraphErrorSubcode=460, com.facebook.sdk:FBSDKGraphRequestErrorParsedJSONResponseKey=
    body =     
        error =         
            code = 190;
            "error_subcode" = 460;
            message = "Error validating access token: The session has been invalidated because the user has changed the password.";
            type = OAuthException;
        ;
    ;
    code = 400;
, NSLocalizedRecoveryOptions=(
    OK,
    Cancel
)

错误消息是“验证访问令牌时出错:由于用户更改了密码,会话已失效。”即使密码没有更改。如果有人知道这里发生了什么,我们将不胜感激。

【问题讨论】:

我们现在在我们的应用程序中也看到了这一点,仅适用于部分用户。正在研究如何解决它,因为我们无法在任何公司设备/帐户上复制它。 这方面有什么更新吗?也有这个问题 问题是一些旧帐户仍然链接到 facebook,所以在上面的代码中我们试图第二次链接它们。我们解决了这个问题,首先确保所有帐户都已取消关联,然后再次关联它们。 【参考方案1】:

如果您在验证访问令牌时遇到错误 - 代码 460- 那么您应该注销用户并调用登录。

【讨论】:

以上是关于升级到适用于 iOS 的 ParseSDK 1.7.5 和 FacebookSDK 4.4.0 后出错的主要内容,如果未能解决你的问题,请参考以下文章

适用于 iOS 的 Facebook SDK v4.0 - 未设置 FBSDKProfile currentProfile

使用适用于 ARC 和多个开发人员的最新 iOS SDK 构建 Facebook

从 prestashop 1.6.1.9 升级到 1.7

XCode 6.4 中 iOS8 Storyboard 中缺少约束图标,适用于最初在早期版本的 iOS 下编写的应用程序

makemigrations 和升级到 Django 1.7 的问题

升级到Java8后,javac仍然显示1.7