当我尝试登录iOS SDK时无法通过FBSDKLoginKit获取访问令牌 [英] Unable to get the access token through FBSDKLoginKit when I am try to login in iOS sdk

查看:207
本文介绍了当我尝试登录iOS SDK时无法通过FBSDKLoginKit获取访问令牌的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用facebook sdk在facebook上共享文本,但是在尝试登录时无法获取访问令牌.登录成功完成,但未获得任何访问令牌. 因此,如果没有访问令牌,我将无法在Facebook上共享文本. 我的代码如下

I am using facebook sdk to share text on facebook but unable to get access token when try to login. login is done successfully but did not get any access token. So without access token I am unable to share the text on facebook. My code are as follows

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


if ([result.token hasGranted:@"publish_actions"]) {
    [[[FBSDKGraphRequest alloc]
      initWithGraphPath:@"me/feed"
      parameters: @{ @"message" : @"hello world"}
      HTTPMethod:@"POST"]
     startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
         if (!error) {
             NSLog(@"Post id:%@", result[@"id"]);
         }
     }];
}

if (error) {
    // Process error
} else if (result.isCancelled) {

    // Handle cancellations
} else {
    // If you ask for multiple permissions at once, you
    // should check if specific permissions missing
    if ([result.grantedPermissions containsObject:@"email"]) {
        // Do work
    }
}

}];

我在FBSDKLoginManager对象的处理程序块中获取了结果,没有错误,但是它不包含令牌或其他数据

i get the result in handler block of FBSDKLoginManager object without error but it does not contain the token or other data

输出如下

请告诉我如何解决此问题 谢谢

please tell me how to resolve this problem Thanks

推荐答案

尝试使用此代码.基于Facebook SDK版本4.0

Try This code. Based on Facebook SDK version 4.0

AppDalegate.m

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
    return [[FBSDKApplicationDelegate sharedInstance] application:application
                                                          openURL:url
                                                sourceApplication:sourceApplication
                                                       annotation:annotation];
}

ViewController.m

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

    }

}

这篇关于当我尝试登录iOS SDK时无法通过FBSDKLoginKit获取访问令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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