我在测试我的应用程序时发现了这个问题,它真的开始惹恼我了。那么环境如下:
当我的应用首次尝试对用户进行身份验证时,它会提供此文本框:(我尝试将其清理一下)
2014-01-30 15:20:31.439 Unifeed[2140:70b] Session is <FBSession: 0xb74f9e0, state:
FBSessionStateClosedLoginFailed,
loginHandler: 0x0, appID: *************, urlSchemeSuffix: ,
tokenCachingStrategy:<FBSessionTokenCachingStrategy: 0xb73bd90>,
expirationDate: (null),
refreshDate: (null), attemptedRefreshDate: 0001-12-30 00:00:00 +0000, permissions:(null)>
2014-01-30 15:20:31.440 Unifeed[2140:70b] Session closed
2014-01-30 15:20:31.440 Unifeed[2140:70b] User logged out
2014-01-30 15:20:31.441 Unifeed[2140:70b] Error occured Error Domain=com.facebook.sdk Code=2
"The operation couldn’t be completed. (com.facebook.sdk error 2.)"
UserInfo=********
{com.facebook.sdk:ErrorLoginFailedReason=com.facebook.sdk:SystemLoginCancelled,
com.facebook.sdk:ErrorInnerErrorKey=Error Domain=com.apple.accounts Code=7 "The operation
couldn’t be completed. (com.apple.accounts error 7.)",
com.facebook.sdk:ErrorSessionKey=<FBSession: 0xb74f9e0, state: FBSessionStateClosedLoginFailed,
loginHandler: 0x0, appID: ************, urlSchemeSuffix:
, tokenCachingStrategy:<FBSessionTokenCachingStrategy:
0xb73bd90>, expirationDate: (null), refreshDate: (null),
attemptedRefreshDate: 0001-12-30 00:00:00 +0000, permissions:(null)>}
2014-01-30 15:20:31.441 Unifeed[2140:70b] User cancelled login
2014-01-30 15:20:31.445 Unifeed[2140:70b] User logged out
我知道这有点令人困惑,但我对它的看法是错误的,因为它认为用户取消了登录过程。事情是我从来没有看到小弹出问我是否要登录或接受权限....所以我添加了Facebook应用程序到手机,它工作...这很好,但如果我有一个用户不是应用程序,但他们已经在手机上登录了FB ....任何人都有任何想法?
我的身份验证代码如下:(几乎只是从FB网站稍加修改)
- (void) facebookSessionChange {
// If the session state is any of the two "open" states when the button is clicked
if (FBSession.activeSession.state == FBSessionStateOpen
|| FBSession.activeSession.state == FBSessionStateOpenTokenExtended) {
// Close the session and remove the access token from the cache
// The session state handler (in the app delegate) will be called automatically
[FBSession.activeSession closeAndClearTokenInformation];
// If the session state is not any of the two "open" states when the button is clicked
} else {
// Open a session showing the user the login UI
[FBSession openActiveSessionWithReadPermissions:permissions
allowLoginUI:YES
completionHandler:
^(FBSession *session, FBSessionState state, NSError *error) {
[self sessionStateChanged:session state:state error:error];
}];
}
}
- (void)sessionStateChanged:(FBSession *)session state:(FBSessionState) state error:(NSError *)error
{
NSLog(@"Session is %@", session);
// If the session was opened successfully
if (!error && state == FBSessionStateOpen){
NSLog(@"Session opened");
// Show the user the logged-in UI
[self userLoggedIn];
return;
}
if (state == FBSessionStateClosed || state == FBSessionStateClosedLoginFailed){
// If the session is closed
NSLog(@"Session closed");
// Show the user the logged-out UI
[self userLoggedOut];
}
// Handle errors
if (error){
NSLog(@"Error occured %@", error);
if ([FBErrorUtility shouldNotifyUserForError:error] == YES){
NSLog(@"Error occured %@", error);
} else {
// If the user cancelled login, do nothing
if ([FBErrorUtility errorCategoryForError:error] == FBErrorCategoryUserCancelled) {
NSLog(@"User cancelled login");
// Handle session closures that happen outside of the app
} else if ([FBErrorUtility errorCategoryForError:error] == FBErrorCategoryAuthenticationReopenSession){
NSLog(@"Session is no longer valid");
} else {
//Get more error information from the error
NSDictionary *errorInformation = [[[error.userInfo objectForKey:@"com.facebook.sdk:ParsedJSONResponseKey"] objectForKey:@"body"] objectForKey:@"error"];
NSLog(@"Error occured : %@", [errorInformation objectForKey:@"message"]);
}
}
// Clear this token
[FBSession.activeSession closeAndClearTokenInformation];
// Show the user the logged-out UI
[self userLoggedOut];
}
}
// Show the user the logged-out UI
- (void)userLoggedOut
{
NSLog(@"User logged out");
}
// Show the user the logged-in UI
- (void)userLoggedIn
{
NSLog(@"User Logged in");
[_delegate doneLogginginToFb];
}
我试过改变我的身份验证方式,但总是遇到同样的问题......有什么想法吗?
由于
A
答案 0 :(得分:4)
我认为我确实在这里重现了您的错误,您的应用程序在设置中被拒绝访问Facebook帐户(出于某种原因,也许您点击了&#34;不允许&#34; ...) 在用户拒绝访问或关闭Facebook设置中的开关后,应用程序将不会再次询问权限,每次尝试连接时都会失败并显示FBErrorCategoryUserCancelled状态。
要解决此问题,请转到设置&gt;一般&gt;重置,然后重置位置&amp;隐私即可。 在运行应用程序之后,您应该能够看到提示请求权限。
答案 1 :(得分:4)
转到Facebook开发者&gt;你的应用&gt;设置&gt;基本
点击 +添加平台
输入您的套件ID
启用单点登录
保存更改。
答案 2 :(得分:2)
我遇到了同样的问题,它让我发疯了。我通过将Facebook SDK更新到最新版本来解决问题。
不确定这是否适合您,但我希望这有助于某人。