繁体   English   中英

Facebook SDK 4.1.0注销不起作用

[英]Facebook sdk 4.1.0 Logout not working

我正在使用以下代码从应用程序注销。

   [[FBSDKLoginManager new] logOut];

   if ([FBSDKAccessToken currentAccessToken]) {
      [FBSDKAccessToken setCurrentAccessToken:nil];
      [FBSDKProfile setCurrentProfile:nil];
   }

仍然是它的旧配置文件才能登录。 如果我杀死了该应用程序并重新启动,那么它将正常工作。

有什么建议我做错了吗?

登录代码-

         FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];         
     [login logInWithReadPermissions:@[@"user_birthday",@"public_profile",@"user_friends",@"email"] handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {

        if (error) {
           // Process error
        } else if (result.isCancelled) {
           // Handle cancellations
        } else {
           if ([result.grantedPermissions containsObject:@"email"]) {

              // Do work
              NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://graph.facebook.com/me?access_token=%@",result.token.tokenString]]];

              //Start the request for the data
              [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
                 NSString *jsonString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
                 NSDictionary *jsonDict = [jsonString JSONValue];
                 [self getFBUserDetailFinished:jsonDict];
              }];
           }
        }
     }];

使用此代码:

FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
[login logOut];

另一种方式 :您在注销方法调用后获得了Facebook用户信息,并且您第二次登录,然后在获取用户数据时没有问题。

- (IBAction)btnFacebookPressed:(id)sender {
    FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
    [login logInWithReadPermissions:@[@"email"] 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];
                 [login logOut];
             }
         }
     }];
}

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

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

    }

}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM