代码:
self.accountStore = [[ACAccountStore alloc]init];
ACAccountType *FBaccountType= [self.accountStore
accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
NSString *appID = @"356775877779749"; //The app ID issued by Facebook
NSDictionary *dictFB = [NSDictionary dictionaryWithObjectsAndKeys:
appID, ACFacebookAppIdKey,
@[@"email"], ACFacebookPermissionsKey,
nil];
[self.accountStore requestAccessToAccountsWithType:FBaccountType options:dictFB completion:
^(BOOL granted, NSError *e) {
if (granted)
{
NSArray *accounts = [self.accountStore accountsWithAccountType:FBaccountType];
//it will always be the last object with single sign on
self.facebookAccount = [accounts lastObject];
ACAccountCredential *facebookCredential = [self.facebookAccount credential];
NSString *accessToken = [facebookCredential oauthToken];
NSLog(@"Successfully logged in. Access Token: %@", accessToken);
FBSDKAccessToken* AccessToken = [FBSDKAccessToken currentAccessToken];
NSLog(@"%@", AccessToken);
[self newFacebookLogin];
} else {
//Failed
NSLog(@"error getting permission: %@",e);
}
}];
我使用上面的代码登录。出于某种原因,NSString *accessToken = [facebookCredential oauthToken] 正确存储了访问 token ,但 FBSDKAccessToken* AccessToken = [FBSDKAccessToken currentAccessToken] 没有。
有什么方法可以将 NSString *accessToken 转换为 FBSDKAccessToken ?
Best Answer-推荐答案 strong>
我遇到了类似的问题,这是由于我没有在 FBSDKProfile 上设置 enableUpdatesOnAccessTokenChange 。不知道为什么它默认不这样做。
[FBSDKProfile enableUpdatesOnAccessTokenChange:TRUE];
或者对于 swift
FBSDKProfile.enableUpdatesOnAccessTokenChange(true)
关于ios - FBSDKAccessToken currentAccessToken 为 nil,我们在Stack Overflow上找到一个类似的问题:
https://stackoverflow.com/questions/35171416/
|