我想在我的应用程序中从facebook获取一些基本信息。我运行这段代码:
FBSession *session = [[FBSession alloc] initWithAppID:APP_ID permissions:nil defaultAudience:FBSessionDefaultAudienceEveryone urlSchemeSuffix:nil tokenCacheStrategy:nil];
NSLog(@"I get this message");
[session openWithCompletionHandler:^(FBSession *session, FBSessionState status, NSError *error) {
NSLog(@"It never calls this");
}];
似乎处理程序从未被调用过。我被带到Facebook并带回来但没有任何反应。有人有什么想法吗?
答案 0 :(得分:2)
我仍然不知道为什么它不起作用,但这就是做了什么。
FBSession *session = [[FBSession alloc] initWithAppID:APP_ID permissions:nil defaultAudience:FBSessionDefaultAudienceEveryone urlSchemeSuffix:nil tokenCacheStrategy:nil];
[FBSettings setDefaultAppID: APP_ID];
[FBSession setActiveSession:session];
[FBSession openActiveSessionWithReadPermissions:@[@"basic_info", @"email"] allowLoginUI:YES completionHandler:^(FBSession *session, FBSessionState status, NSError *error) {
if ([session isOpen]) {
[FBRequestConnection
startForMeWithCompletionHandler:^(FBRequestConnection *connection,
id<FBGraphUser> FBUser,
NSError *error) {
if (!error){
//do whatever you need to.
}
}];
}
}];