- In ios 9.2 when i login facebook get error Invalid_access token.
- But when i login with app register account it get successfully login facebook.
- 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];
}
最佳答案
试试这个
-(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);
}
}];
}
}
}
}];
}
关于ios - Facebook 错误 Invalid_access token,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35053919/