我尝试了下面的代码,但它正在处理错误。
- (void) openActiveSessionWithPermissions: (NSArray *) arr
{
if ([FBSession activeSession].state == FBSessionStateCreatedTokenLoaded){
[self openWithUI:NO permissions:arr];
} else if ([FBSession activeSession].state == FBSessionStateOpen || [FBSession activeSession].state == FBSessionStateOpenTokenExtended){
[[FBSession activeSession] closeAndClearTokenInformation];
} else {
[[FBSession activeSession] closeAndClearTokenInformation];
[self openWithUI:YES permissions:arr];
}
}
- (void) openWithUI: (BOOL) UI permissions: (NSArray *) permissions
{
[FBSession openActiveSessionWithReadPermissions:permissions allowLoginUI:UI completionHandler:^(FBSession *session, FBSessionState state, NSError *error) {
if (error) {
[self.delegate didReceieveError:[error description]];
} else {
[self.delegate didTakeAccessToken:session.accessTokenData.accessToken];
}
}];
}
我找不到自己的错误。
获得accesToken
的最佳方式是什么?感谢。
答案 0 :(得分:0)
试试这个:
[FBSession openActiveSessionWithReadPermissions:@[@"basic_info", @"email"]
allowLoginUI:YES
completionHandler:
^(FBSession *session, FBSessionState state, NSError *error)
{
if (FBSession.activeSession.isOpen)
{
[[FBRequest requestForMe] startWithCompletionHandler:
^(FBRequestConnection *connection, NSDictionary<FBGraphUser> *user, NSError *error)
{
if (!error)
{
//Get AccessToken
NSString *aStrFBAccessToken = [[[FBSession activeSession] accessTokenData] accessToken];
}
}];
}
}];