您已经授权了Facebook,iOS [英] You have already authorized facebook, iOS

查看:113
本文介绍了您已经授权了Facebook,iOS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在我有一个iOS应用程序,使用Facebook SDK登录使用用户的Facebook帐户,显然你知道。这里是我用来做这些东西的代码。

   - (void)loginButtonClicked 
{
FBSDKLoginManager * login = [[FBSDKLoginManager alloc] init];
[login logInWithReadPermissions:@ [@email] fromViewController:self handler:^(FBSDKLoginManagerLoginResult * result,NSError * error)
{
if(error)
{
//进程错误
}
else if(result.isCancelled)
{
//处理取消
}
else
{
if([result.grantedPermissions containsObject:@email])
{
NSLog(@result is:%@,result);
[self fetchUserInfo];
}
}
}];


- (void)fetchUserInfo
{
if([FBSDKAccessToken currentAccessToken])
{
NSLog(@令牌可用:%@,[[FBSDKAccessToken currentAccessToken] tokenString]);

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

}
}

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



我想要的他们只需要标签登录按钮,然后加载圈就会显示和成功。



有任何想法吗?

解决方案

选择1



如果您按 / code>按钮,调用此



删除所有授予的权限

  [[FBSDKGraphRequest alloc] initWithGraphPath:@me / permissions参数:nil 
HTTPMethod:@DELETE] startWithCompletionHandler:^(FBSDKGraphRequestConnection * connection,id result,NSError *错误){

if(error)
{
//进程错误
}
else if(result.isCancelled)
{
//处理取消
}
else
{
//调用您的登录操作并创建新会话
[self loginButtonClicked];
}

}];

选择2



如果要清除当前会话使用,如

   - (void)loginButtonClicked 
{
FBSDKLoginManager * login = [[FBSDKLoginManager alloc] init];
[login logOut];
[FBSDKAccessToken setCurrentAccessToken:nil];
//然后继续相同的过程

更新



如果你想绕过连接

   - (void)loginButtonClicked 
{
如果FBSDKAccessToken.currentAccessToken!= nil
{
//已经使用请求的权限登录
}
else
{
//开始登录过程
}
}

Swift



删除所有已授予的Permisson

 code> FBSDKGraphRequest(graphPath:me / permissions,参数:nil,HTTPMethod:DELETE)。startWithCompletionHandler({(connection:FBSDKGraphRequestConnection,result:AnyObject,error:NSError) - > Void in 
如果错误!{
//进程错误
}
如果result.isCancelled {
//处理取消
}
else {
//调用您的登录操作并创建新会话
self.loginButtonClicked()
}

})

选择2 / p>

如果要清除当前会话使用,如

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

//然后继续相同的进程

}

更新

  func loginButtonClicked(){
如果FBSDKAccessToken.currentAccessToken!= nil {
//已经使用请求的权限登录
}
else {
//启动登录过程
}
}


Now I have an iOS Application that using facebook SDK to login using user facebook account, obviously you know that. And here is my code which i use to do this stuff.

-(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);
             }
         }];

    }
}

Problem is when user deleted app and they install then signin back again, the dialog of facebook login show "You have already authorized {ApplicationName}" and user must click OK to return my app.

All I want that they only need tab to login button then a loading circle show up and success.

Any idea to do that?

解决方案

Choice-1

if you press the Login button, call this

delete all granted permisson

[[[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];
     }

 }];

Choice-2

if you want to clear the current session use like

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

update

if you want to bypass the connection

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

Swift

delete all granted permisson

  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()
}

})

Choice-2

if you want to clear the current session use like

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

// then continue the same process

}

update

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

这篇关于您已经授权了Facebook,iOS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆