当我尝试在iOS sdk中login时,无法通过FBSDKLoginKit获取访问令牌

我正在使用Facebook sdk在Facebook上分享文本,但尝试login时无法获取访问令牌。 login成功完成,但没有获得任何访问令牌。 所以没有访问令牌,我无法在Facebook上分享文本。 我的代码如下

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对象的处理程序块中得到的结果没有错误,但它不包含令牌或其他数据

输出如下

在这里输入图像说明

请告诉我如何解决这个问题谢谢

试试这个代码。 基于Facebook SDK版本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); } }]; } }