Facebook 错误 Invalid_access 令牌

Facebook Error Invalid_access token

  1. In ios 9.2 when i login facebook get error Invalid_access token.
  2. But when i login with app register account it get successfully login facebook.
  3. my image here.

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), accounts{username},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];
}

转到 developers.facebook.com -> 在该设置中添加联系人电子邮件和单点登录是

然后点击应用审核 ->是否要让一般 public 可以使用此应用程序及其所有实时功能? 这应该是。

试试这个

-(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), accounts{username},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);

                         }
                     }];
                }
            }
        }
    }];
}