2015-07-12 105 views
7

我正在使用Facebook创建新用户或登录到解析。到应用程序中使用的Facebook登录 检查用户是否已修改Facebook权限对于应用程序

  • 用户

    1. 用户登录提示是接受的权限。
    2. 用户接受应用程序请求的所有权限。

    4.用户取消了应用程序的权限(从Facebook删除应用程序)

    我想知道什么是我们要检查用户是否有改变的Facebook应用程序的授权状态的方式。

    如何检查?我们如何知道它不再连接?

    FBSDKAccessToken.currentAccessToken();不能完成这项工作,因为它只能检查令牌是否存在于设备中。

    I.E .:用户转到Facebook应用程序设置并从列表中删除应用程序。

    p.s .:请帮助把这个问题投票,因为它真的很难找到解决方案。谢谢!!

    谢谢

  • 回答

    3

    Handling an Invalidated Session

    We cannot know if the cached Facebook session is valid until we attempt to make a request to the API. A session can become invalidated if a user changes their password or revokes the application's privileges. When this happens, the user needs to be logged out. We can identify an invalid session error within a FBSDKGraphRequest completion handler and automatically log the user out.

    FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:nil]; 
        [request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) { 
         if (!error) { 
          // handle successful response 
         } else if ([[error userInfo][@"error"][@"type"] isEqualToString: @"OAuthException"]) { // Since the request failed, we can check if it was due to an invalid session 
          NSLog(@"The facebook session was invalidated"); 
          [PFFacebookUtils unlinkUserInBackground:[PFUser currentUser]]; 
         } else { 
          NSLog(@"Some other error: %@", error); 
         } 
        }]; 
    

    来源:Integrate Login with Facebook

    +0

    你会碰巧知道swift3的更新代码吗? – DevKyle

    0

    我认为你可以找到你正在寻找一个在这里的回答:

    https://developers.facebook.com/docs/facebook-login/ios/permissions

    你既可以:

    1)检查是否存在错误自己:

    let token = FBSDKAccessToken.currentAccessToken() 
    if token.hasGranted("publish_actions") //Or whatever other permission you're checking 
    

    2)无论如何执行一些操作,检查错误:

    if error.userInfo[FBSDKGraphRequestErrorGraphErrorCode] == 200 
    { 
        //Handle missing permissions here 
    } 
    

    我猜的currentAccessToken将缓存从他们登录的最后一次信息,所以第二个选项可能是要走的路。

    相关问题