Facebook 错误 Invalid_access 令牌
Posted
技术标签:
【中文标题】Facebook 错误 Invalid_access 令牌【英文标题】:Facebook Error Invalid_access token 【发布时间】:2016-01-28 06:03:15 【问题描述】:在 ios 9.2 中,当我登录 facebook 时出现错误 Invalid_access token。 但是当我使用应用注册帐户登录时,它会成功登录 facebook。 我的图片在这里。
MYviewController.m 文件
-(void)loginButtonClicked
FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
login.loginBehavior = FBSDKLoginBehaviorWeb;
[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"])
if ([FBSDKAccessToken currentAccessToken])
[[[FBSDKGraphRequest alloc] initWithGraphpath:@"me" parameters:@@"fields": @"first_name, last_name, picture.type(normal), accountsusername,email, gender, locale, timezone, about"]
startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error)
if (!error)
NSLog(@"fetched user:%@", result);
NSString *fbAccessToken = [FBSDKAccessToken currentAccessToken].tokenString;
NSLog(@"fbAccessToken=>%@", fbAccessToken);
];
];
MYAppdelegate.m 文件。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
[[FBSDKApplicationDelegate sharedInstance] application:application
didFinishLaunchingWithOptions:launchOptions];
return YES;
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation
return [[FBSDKApplicationDelegate sharedInstance] application:application
openURL:url
sourceApplication:sourceApplication
annotation:annotation];
- (void)applicationDidBecomeActive:(UIApplication *)application
[FBSDKAppEvents activateApp];
【问题讨论】:
【参考方案1】:试试这个
-(void)loginButtonClicked
/********* logout the current session ************/
FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
[login logOut];
[FBSDKAccessToken setCurrentAccessToken:nil];
[FBSDKProfile setCurrentProfile:nil];
/********* logout the current session ************/
/********* start the new session for login ************/
// FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
login.loginBehavior = FBSDKLoginBehaviorWeb;
[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"])
if ([FBSDKAccessToken currentAccessToken])
[[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:@@"fields": @"first_name, last_name, picture.type(normal), accountsusername,email, gender, locale, timezone, about"]
startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error)
if (!error)
NSLog(@"fetched user:%@", result);
NSString *fbAccessToken = [FBSDKAccessToken currentAccessToken].tokenString;
NSLog(@"fbAccessToken=>%@", fbAccessToken);
];
];
【讨论】:
【参考方案2】:转到developers.facebook.com ->在该设置中添加联系电子邮件和单点登录是
然后点击App review ->您想让这个应用程序及其所有实时功能向公众开放吗? 这应该是。
【讨论】:
以上是关于Facebook 错误 Invalid_access 令牌的主要内容,如果未能解决你的问题,请参考以下文章
科尔多瓦:android 4.1 中的 facebook 登录错误“为 facebook 登录配置错误”
facebook 错误:会话已关闭且未正常关闭(phonegap 构建/facebook 插件错误)
将应用程序配置为 facebook 错误:“应用程序配置错误以进行 Facebook 登录..” [重复]
登录 Facebook 时出现 com.facebook.sdk 错误 2
Facebook 共享对话框:权限错误 - OAuth“Facebook 平台”“insufficient_scope (#200) 权限错误”