[英]ios facebook sdk access token gets cleared every time I run my app from Xcode?
使用Facebook帳戶登錄后,一切正常,除了每次啟動應用程序時令牌會自動清除之外,因此它要求我再次登錄,我在didFinishLaunchingWithOptions
使用以下代碼來檢查活動會話:
if (FBSession.activeSession.state == FBSessionStateCreatedTokenLoaded) {
NSLog(@"Found a cached session");
// If there's one, just open the session silently, without showing the user the login UI
[FBSession openActiveSessionWithReadPermissions:@[@"public_profile", @"email", @"user_friends",@"publish_actions,publish_stream"]
allowLoginUI:NO
completionHandler:
^(FBSession *session, FBSessionState state, NSError *error) {
NSLog(@"session exp. = %@",session.accessTokenData.expirationDate);
[self sessionStateChanged:session state:state error:error delegate:_delegate];
if (error) {
NSLog(@"error: %@",error.localizedDescription);
}
[[NSUserDefaults standardUserDefaults]setObject:[Utils languageSelectedStringForKey:@"Logout"] forKey:@"fbState"];
[[NSUserDefaults standardUserDefaults]synchronize];
[self sessionStateChanged:session state:state error:error delegate:nil];
}];
// If there's no cached session, we will show a login button
} else {
[[NSUserDefaults standardUserDefaults]setObject:[Utils languageSelectedStringForKey:@"Login with Facebook"] forKey:@"fbState"];
[[NSUserDefaults standardUserDefaults]synchronize];
NSLog(@"no cached session -> show a login button");
// UIButton *loginButton = [self.customLoginViewController loginButton];
// [loginButton setTitle:@"Log in with Facebook" forState:UIControlStateNormal];
}
因此,將打印“發現已緩存的會話”消息,但是當我檢查會話時發現它已清除,我注意到的是未調用方法openActiveSessionWithReadPermissions
!
任何建議,請!
我發現了問題,我使用了錯誤的權限,該權限不允許我存儲會話,因此我如下編輯了權限:
@[@"public_profile", @"email", @"user_friends",@"publish_actions"]
因此,在我刪除publish_stream
一切工作正常。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.