【问题标题】:You have already authorized facebook, iOS您已经授权facebook、iOS
【发布时间】:2016-05-07 05:27:24
【问题描述】:

现在我有一个 iOS 应用程序,它使用 facebook SDK 使用用户 facebook 帐户登录,显然你知道这一点。这是我用来做这些事情的代码。

-(void)loginButtonClicked
{
    FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
    [login logInWithReadPermissions:@[@"email"] fromViewController:self handler:^(FBSDKLoginManagerLoginResult *result, NSError *error)
     {
         if (error)
         {
             // Process error
         }
         else if (result.isCancelled)
         {
             // Handle cancellations
         }
         else
         {
             if ([result.grantedPermissions containsObject:@"email"])
             {
                 NSLog(@"result is:%@",result);
                 [self fetchUserInfo];
             }
         }
     }];
}

- (void)fetchUserInfo
{
    if ([FBSDKAccessToken currentAccessToken])
    {
        NSLog(@"Token is available : %@",[[FBSDKAccessToken currentAccessToken]tokenString]);

        [[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:@{@"fields": @"id, name, link, email, birthday, bio, location, friends, hometown, friendlists"}]
         startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
             if (!error)
             {
                 NSLog(@"resultis:%@",result);
             }
             else
             {
                 NSLog(@"Error %@",error);
             }
         }];

    }
}

问题是当用户删除应用程序并安装然后再次登录时,Facebook 登录对话框显示“您已经授权 {ApplicationName}”,用户必须单击确定才能返回我的应用程序。

我只希望他们只需要选项卡即可登录按钮,然后显示加载圈并成功。

有什么想法吗?

【问题讨论】:

  • 你需要什么输出
  • 如果用户按下登录按钮,你不想再看到这个You have already authorized {ApplicationName}
  • 是的,我想要这个,我该怎么做?

标签: ios objective-c facebook


【解决方案1】:

选择 1

如果您按下Login 按钮,请调用此按钮

删除所有授予的权限

[[[FBSDKGraphRequest alloc] initWithGraphPath:@"me/permissions" parameters:nil 
HTTPMethod:@"DELETE"] startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {

 if (error)
     {
         // Process error
     }
     else if (result.isCancelled)
     {
         // Handle cancellations
     }
     else
     {
      // call your login action and create the new session
       [self loginButtonClicked];
     }

 }];

选择 2

如果你想清除当前会话使用like

-(void)loginButtonClicked
{
FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
[login logOut];
[FBSDKAccessToken setCurrentAccessToken:nil];
// then continue the same process

更新

如果你想绕过连接

 -(void)loginButtonClicked
{
if FBSDKAccessToken.currentAccessToken != nil
{
  // already logged in with the requested permissions 
}
else
{
  // start the login process
}
}

斯威夫特

删除所有授予的权限

  FBSDKGraphRequest(graphPath: "me/permissions", parameters: nil,  HTTPMethod: "DELETE").startWithCompletionHandler({(connection:  FBSDKGraphRequestConnection, result: AnyObject, error: NSError) -> Void in
if error! {
    // Process error
}
else if result.isCancelled {
    // Handle cancellations
}
else {
    // call your login action and create the new session
    self.loginButtonClicked()
}

})

选择 2

如果你想清除当前会话使用like

func loginButtonClicked() {
var login: FBSDKLoginManager = FBSDKLoginManager()
login.logOut()
FBSDKAccessToken.currentAccessToken = nil

// then continue the same process

}

更新

func loginButtonClicked() {
if FBSDKAccessToken.currentAccessToken != nil {
    // already logged in with the requested permissions
}
else {
    // start the login process
}
}

【讨论】:

  • 抱歉我的英语不好,我的意思是,我不想要清晰的会话。我想当用户已经获得授权时,我们可以如何跳过该步骤并直接将用户放入应用程序
  • 好的,但是当用户删除应用程序并重新登录时,他们仍然看到这个屏幕appcoda.com/wp-content/uploads/2014/05/t13_7_authorize.jpg 我希望他们不需要看到这个并直接自动执行登录,这样做可以吗?
  • @vietnguyen09-所有答案都在我的答案中可用,如果您当时注销使用选项 1 ,选项 2 ,它会删除您的所有权限和会话,如果您按下登录按钮,它会显示登录详情兄弟
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-04-10
  • 2017-08-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-10-01
相关资源
最近更新 更多