【发布时间】:2014-10-18 20:00:35
【问题描述】:
iOS 中的 Facebook SDK 有问题。一切正常,但我的登录流程有问题。当用户点击“登录 Facebook”按钮时,他会被定向到 Facebook 以允许我的应用程序获得权限。没关系。但是,当 iOS 从浏览器更改为我的应用程序并尝试发出请求时,我收到以下错误消息:
FBSDKLog: Error for request to endpoint 'search?q=concert&type=event&limit=10': An open FBSession must be specified for calls to this endpoint.
当我关闭应用程序并重新启动它并执行我的请求时,它可以正常工作。我得到了我的要求。这是我的代码,我知道它不是很整洁。
ViewdidLoad:
- (void)viewDidLoad {
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appDidEnterForeground:) name:UIApplicationWillEnterForegroundNotification object:nil];
//Some other Code
if ([[FBSession activeSession]state])
{
NSLog(@"User is logged in");
[loginView setHidden:TRUE];
} else {
// try to open session with existing valid token
NSArray *permissions = [[NSArray alloc] initWithObjects:
@"user_events",
nil];
FBSession *session = [[FBSession alloc] initWithPermissions:permissions];
[FBSession setActiveSession:session];
if([FBSession openActiveSessionWithAllowLoginUI:NO]) {
} else {
NSLog(@"User is logged out");
//Create the FB Login-Button
loginView = [[FBLoginView alloc] initWithReadPermissions:@[@"user_events"]];
// Align the button in the center horizontally
loginView.frame = CGRectOffset(loginView.frame, (self.view.center.x - (loginView.frame.size.width / 2)), 200);
[self.view addSubview:loginView];
}
}
[self getEvents];
}
获取事件:
-(void)getEvents{
//Get General Events
[FBRequestConnection startWithGraphPath:@"search?q=concert&type=event&limit=10"
completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if (!error) {
//Some Code
else {
// An error occurred, we need to handle the error
// See: https://developers.facebook.com/docs/ios/errors
}
}];
}
appDidEnterForeground
- (void)appDidEnterForeground:(NSNotification *)notification {
NSLog(@"App did enter forground again.");
[self viewDidLoad];
}
【问题讨论】:
标签: ios facebook sdk facebook-login