我正在使用 Facebook SDK 来获取应用程序中的用户组
但我得到一个空访问 token 。
我在 viewDidLoad
中的代码如下。
- (void)viewDidLoad
{
[super viewDidLoad];
self.session = [[FBSession alloc] initWithAppID:appID permissions[@"basic_info",@"user_groups",@"email"] defaultAudience:FBSessionDefaultAudienceEveryone urlSchemeSuffix:nil tokenCacheStrategy:nil];
[FBSession openActiveSessionWithReadPermissions[@"basic_info",@"user_groups",@"email"] allowLoginUI:YES completionHandler:^(FBSession *session, FBSessionState status, NSError *error) {
NSLog(@"Error in Session Opening %@",error.description);
NSLog(@"access Token %@",session.accessTokenData.accessToken);
[FBRequestConnection startWithGraphPath"me/groups" parameters:nil HTTPMethod"GET" completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if (!error) {
NSLog(@"%@",result);
}else
{
NSLog(@"Error %@",error.description);
}
}];
}];
}
这段代码的输出是:-
Error in Session Opening (null)
access Token (null)
Error Error Domain=com.facebook.sdk Code=5 "The operation couldn’t be completed. (com.facebook.sdk error 5.)" UserInfo=0x1090acc80 {com.facebook.sdk:HTTPStatusCode=400, com.facebook.sdkarsedJSONResponseKey={
body = {
error = {
code = 2500;
message = "An active access token must be used to query information about the current user.";
type = OAuthException;
};
};
code = 400;
}}
如您所见,访问 token 为空..
我做错了什么?
在这段代码中是否应该添加一些额外的东西?
谢谢
你想要这个:
session.accessTokenData.accessToken
'session' 是你的 FBSession
你可以从中得到...
if (FBSession.activeSession.state == FBSessionStateCreatedTokenLoaded)
{
// If there's one, just open the session silently, without showing the user the login UI
[FBSession openActiveSessionWithReadPermissions[@"public_profile", @"email"]
allowLoginUI:NO
completionHandler:^(FBSession *session, FBSessionState state, NSError *error)
{
NSLog(@"%@", session.accessTokenData.accessToken);
}];
}
关于ios - 如何从 FBSession 获取访问 token ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21440673/
欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) | Powered by Discuz! X3.4 |