I had a similar problem.
After initialising FBSDKLoginManager
I added a line to flush out the data and the (Facebook)Token:
FBSDKLoginManager *loginmanager= [[FBSDKLoginManager alloc]init];
[loginmanager logOut];
Hope this helps.
Thus, exactly as the OP asks, "am I missing something"?
Yes, the following standard example code which is seen everywhere, is simply wrong:
-(IBAction)facebookLoginClick:(id)sender
{
FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
---- ONE MAGIC LINE OF CODE IS MISSING HERE ----
[login logInWithReadPermissions:@[@"email"]
handler:^(FBSDKLoginManagerLoginResult *result, NSError *error)
{
if (error) {...}
else if (result.isCancelled) {...}
else { // (NB for multiple permissions, check every one)
if ([result.grantedPermissions containsObject:@"email"])
{ NSLog(@"%@",result.token); }
}
}];
}
you must do this:
-(IBAction)facebookLoginClick:(id)sender
{
FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
[login logOut]; //ESSENTIAL LINE OF CODE
[login logInWithReadPermissions:@[@"email"]
handler:^(FBSDKLoginManagerLoginResult *result, NSError *error)
{
if (error) {...}
else if (result.isCancelled) {...}
else { // (NB for multiple permissions, check every one)
if ([result.grantedPermissions containsObject:@"email"])
{ NSLog(@"%@",result.token); }
}
}];
}
Otherwise, very simply, the app will not work if the user happens to change FB accounts on the device. (Unless they happen to for some reason re-install the app!)
Once again - the popular sample code above simply does not work (the app goes in to an endless loop) if a user happens to change FB accounts. The logOut
call must be made.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…