xcode 项目总是得到 facebook 登录失败状态
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12046679/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
xcode project always gets facebook login fail status
提问by Tony Xu
I encountered a facebook login problem. I installed FB SDK 3.0 and sample projects seemly run well --- not quite sure though. When I create a button in my own project and try to log in to Facebook, I always get FBSessionStateClosedLoginFailed from sessionStateChanged method, although I apparently get the page "You have already authorized this app. Press Okay to continue". I also tried log out through Simulator Safari facebook page, and re-launched my project and I got new username/password page and I then logged in, but I still get FBSessionStateClosedLoginFailed!
我遇到了 facebook 登录问题。我安装了 FB SDK 3.0 并且示例项目似乎运行良好 --- 不过不太确定。当我在我自己的项目中创建一个按钮并尝试登录 Facebook 时,我总是从 sessionStateChanged 方法得到 FBSessionStateClosedLoginFailed,尽管我显然得到了页面“你已经授权这个应用程序。按确定继续”。我还尝试通过 Simulator Safari facebook 页面注销,并重新启动我的项目,我得到了新的用户名/密码页面,然后我登录了,但我仍然收到 FBSessionStateClosedLoginFailed!
A few more observations. 1, I got FBSessionStateClosedLoginFailed thru NSLog, the log comes up right after I clicked Okay button on the Facebook page "You have already authorized this app. 2, I tried clean xcode project cache, but no help.
还有一些观察。1,我通过 NSLog 得到 FBSessionStateClosedLoginFailed,在我点击 Facebook 页面上的 OK 按钮后立即出现日志“你已经授权了这个应用程序。2,我尝试清理 xcode 项目缓存,但没有帮助。
Kind of frustrated. I wonder if any of you can help on this problem. Appreciated! -Tony
有点沮丧。我想知道你们中是否有人可以帮助解决这个问题。赞赏!-托尼
Addition: I did a bit more research, and I found what I have is probably a typical problem, as Facebook highlight here ("Pro-tip 3: Complete all iOS App Settings" section in page http://developers.facebook.com/docs/howtos/login-with-facebook-using-ios-sdk/). The image with a big red cross over iPhone is exactly what I have. From xcode project, I click my login button, and I'm directed to this page, and every time I have to click "Okay" on this page (let me call it Okay_page) to go back to my app in Simulator, however with login status as FBSessionStateClosedLoginFailed. I checked bundle ID, I have it correct. I don't have a 'YOUR_IPHONE_APP_STORE_ID' yet, which I believe I need pay Apple to get and I will do it later but not while I'm still working on it.
另外:我做了更多的研究,我发现我遇到的问题可能是一个典型的问题,正如 Facebook 在这里强调的那样(“专业提示 3:完成所有 iOS 应用设置”页面http://developers.facebook.com 中的部分/docs/howtos/login-with-facebook-using-ios-sdk/)。iPhone 上带有大红叉的图像正是我所拥有的。在 xcode 项目中,我单击我的登录按钮,然后我被定向到此页面,每次我必须在此页面上单击“确定”(让我称之为 Okay_page)返回到我在模拟器中的应用程序时,但是登录状态为 FBSessionStateClosedLoginFailed。我检查了bundle ID,我有正确的。我还没有“YOUR_IPHONE_APP_STORE_ID”,我相信我需要付钱给 Apple 才能获得,我稍后会这样做,但不会在我还在努力的时候做。
Now get a couple of questions: 1, Do I have to have YOUR_IPHONE_APP_STORE_ID to skip this Okay_page? 2, Does this (not automatically re-directed back to my app from this Okay_page) have anything to do with that I always get a login status of FBSessionStateClosedLoginFailed when I manually click Okay in this Okay_page and return to my app in Simulator? In another word, is (that I have to manually click Okay to get back to my app in Simulator) (the reason I got a status of FBSessionStateClosedLoginFailed)?
现在得到几个问题: 1,我是否必须有 YOUR_IPHONE_APP_STORE_ID 才能跳过这个 Okay_page?2,这(不会自动从这个Okay_page重定向回我的应用程序)是否与我在这个Okay_page中手动单击Okay并返回到我在模拟器中的应用程序时总是获得FBSessionStateClosedLoginFailed的登录状态有关?换句话说,是(我必须手动单击“确定”才能返回模拟器中的应用程序)(我获得 FBSessionStateClosedLoginFailed 状态的原因)?
回答by user832676
Did you have set this function in AppDelegate?
你有没有在 AppDelegate 中设置过这个功能?
-(BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
return [FBSession.activeSession handleOpenURL:url];
}
回答by Gonzalo
I had the same issue:
我有同样的问题:
- We created the facebook app (developer.facebook.com) setting our bundle id (ex. com.MyCompany.MyApp)
- Off course, created our iOS app with the same bundle id
- After delivered our app to the client, he changed the bundle id without notify us.
- 我们创建了 facebook 应用程序 (developer.facebook.com),设置了我们的 bundle id(例如 com.MyCompany.MyApp)
- 当然,使用相同的 bundle id 创建了我们的 iOS 应用程序
- 将我们的应用程序交付给客户后,他在没有通知我们的情况下更改了捆绑包 ID。
Obviously he started to get FBSessionStateClosedLoginFailed errors!
显然他开始收到 FBSessionStateClosedLoginFailed 错误!
So, you probably have different bundle id's between your iOS project and your Facebook App.
因此,您的 iOS 项目和 Facebook 应用程序之间可能有不同的包 ID。
回答by Buyin Brian
I had this error and couldn't resolve it for quite some time. It turns out that if you are using the native iOS Facebook account in settings and choose "no" for allow Facebook for this app, the app is blocked by the OS. You will always get the FBSessionStateClosedLoginFailed error and there is nothing you can do inside the code to fix this (99% sure). The best you can do is alert the user to check out the settings.
我遇到了这个错误,很长一段时间都无法解决。事实证明,如果您在设置中使用本机 iOS Facebook 帐户并选择“否”允许 Facebook 使用此应用程序,该应用程序将被操作系统阻止。您将始终收到 FBSessionStateClosedLoginFailed 错误,并且您无法在代码中执行任何操作来解决此问题(99% 肯定)。您能做的最好的事情就是提醒用户检查设置。
回答by Iqbal Khan
i am typing wrong line in given below method. self.session was nil
我在下面给出的方法中输入了错误的行。self.session 为零
return [self.session handleOpenURL:url];
it should be
它应该是
return [[FBSession activeSession] handleOpenURL:url];
Use Following Method.
使用以下方法。
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation {
// attempt to extract a token from the url
return [[FBSession activeSession] handleOpenURL:url];
// return [self.session handleOpenURL:url];
}
回答by fannheyward
I fixed this problem after I reset the simulator. iOS Simulator - Reset Content and Settings...
, hope to help.
我在重置模拟器后解决了这个问题。iOS Simulator - Reset Content and Settings...
,希望有所帮助。
回答by Matt Connolly
I had this issue because I was calling [FBSession.activeSession close]
in my applicationDidEnterBackground:
app delegate callback. This closed the session so that when the redirect brought the app back up to open the session, it failed because it had been put into the closed state.
我遇到这个问题是因为我正在调用[FBSession.activeSession close]
我的applicationDidEnterBackground:
应用程序委托回调。这关闭了会话,因此当重定向使应用程序重新打开以打开会话时,它失败了,因为它已被置于关闭状态。
Make sure that you're not closing the session anywhere before you get to the Okay page.
确保在进入“确定”页面之前没有在任何地方关闭会话。
回答by fnc12
go to Facebook.com. Open your application on the left panel -> Status & Review -> there is a toggle with text "Do you want to make this app and all its live features available to the general public?". Turn it on
去 Facebook.com。在左侧面板上打开您的应用程序 -> 状态和 -> 有一个带有文本的切换开关,“您想将此应用程序及其所有实时功能提供给公众吗?”。打开它
回答by Vaibhav Saran
well. I followed FBLoginCustomUISample
somewhere on github.com
and it was a working example of facebook
login implementation from facebook
itself. You can also read my workaround while creating facebook
login feature in a iOS app. Here is a link form me:
好。我关注了FBLoginCustomUISample
某个地方github.com
,它本身就是一个facebook
登录实现的工作示例facebook
。您还可以facebook
在 iOS 应用程序中创建登录功能时阅读我的解决方法。这是我的链接: