facebook-ios-sdk 注销问题
我在这里看到了很多有关 Facebook Graph API 的问题,但我仍然没有找到使用它进行简单“登录”/“注销”操作的解决方案。看起来单点登录风格造成的混乱多于好处。
我想知道是否可能出现以下情况:
- 进入应用程序(未创建
accessToken
/expirationDate
)。 - 通过调用
authorize:delegate:
方法使用 SSO 执行登录(应用程序进入后台并在“全局”范围(Facebook 应用程序/移动 Safari)中进行登录,要求提供用户凭据。 - 回车在应用程序中(现已登录,
accessToken
和expirationDate
均保存到NSUserDefaults
), - 通过调用
logout 执行注销:
方法(现已注销,accessToken
和expirationDate
均从NSUserDefaults
中删除) - 尝试再次执行登录,使用完全相同的方法2. 中完成的步骤
我意识到,当我调用 logout:
时,我确实从我的应用程序范围内从 Facebook 注销(accessToken
已失效),而不是从global
范围(Facebook 应用程序/移动 Safari)。在 5.) 中,当我尝试再次登录时,应用程序会转到后台,并在 Facebook 中再次尝试登录。应用程序/移动 Safari 和往常一样,但是我收到一个屏幕,显示我已经登录:
您已经授权
...
。按“确定”继续。 以...
身份登录(不是您?)。
对于刚刚在我的应用程序中注销的用户来说,这是一种奇怪的行为。 我的问题是:
“我可以真的从我的应用程序内部从 facebook(我的意思是“全球”范围)注销吗?这也会影响使用 facebook 凭据的其他应用程序。但是,如果我不能为此,我怎样才能避免上述“奇怪的行为”
?
I have seen a lot of questions here regarding the Facebook Graph API but I still haven't find a solution for simple 'login'/'logout' operations using it. Looks like the Single Sign-On style is causing more confusion than benefits.
I'd like to know if it is possible have the following situation:
- Enter in the app (no
accessToken
/expirationDate
created). - Perform a login using SSO by calling
authorize:delegate:
method (application goes background and the login is made in the 'global' scope (Facebook App/Mobile Safari), asking for the user credentials. - Enter back in the app (now logged in, both
accessToken
andexpirationDate
are saved toNSUserDefaults
). - Perform a logout by calling the
logout:
method (now logged out, bothaccessToken
andexpirationDate
are removed fromNSUserDefaults
) - Attempt to perform a login again, with exactly the same steps done in 2.
I realize that when I call logout:
, I do really log out from Facebook (accessToken
is invalidated) from my App scope, not from the global
scope (Facebook App/Mobile Safari). In 5.) when I try to log in again, the application goes to background and the login attempt is made again in Facebook App/Mobile Safari as usual, however I'm getting a screen saying that I'm already logged in:
You have already authorized
...
. Press "Okay" to continue.
Logged in as...
(Not You?).
It's a strange behavior for the user that has just logged out in my App.
My question is:
"Can I really log out from facebook (I mean 'global' scope) from inside my App? This would affect other apps using the facebook credentials too. However, if I can't to do this, how can I avoid the 'strange behavior' describe above?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
爱德华多,
我感受到你的痛苦!我花了一天的大部分时间来研究这个问题。我发现,当您使用 SSO 和调用时:
从您的代码调用:
Facebook API 方法:
facebook API 确实会使访问令牌和过期日期变量无效并尝试删除移动 Safari cookie,但由于某种原因,可能是 Apple 的错误,cookie 并未真正删除。因此,当您下次尝试登录时,您的移动 Safari 将看到该 cookie,并显示:
在 Facebook 找到修复程序或 Apple 修复其损坏的 API 之前,我们必须通过 Safari 绕过 SSO。以下是我为了强制使用旧的登录对话框而对 Facebook.m 所做的更改。如果您使用这些更改,它们可能不会永远有效,但我猜它们会持续很长时间。另外,为了确保这适用于最新的 facebook API,我已将其更新到本文中的最新版本(2011 年 11 月构建)。
从您的代码调用:
Facebook API 方法:
如果这对您有帮助,请评价此帖子和我的帖子,以帮助其他人找到它。
gadildafissh
Eduardo,
I feel your pain! I spent the better part of a day working on this issue. I have discovered that when you use SSO and the call:
Called from your code:
Facebook API method:
The facebook API does invalidate the access token and expirationdate variables and attempts to delete the mobile Safari cookies, but for some reason, probably Apple's fault the cookies are not really deleted. So when you attempt to login in the next time your mobile Safari will see the cookie and it says:
Until either Facebook finds a fix or Apple fixes their broken API we must bypass SSO through Safari. Below are the changes I made to Facebook.m in order to force the old login dialog. If you used these changes they may not work forever but it is my guess that they will work for a very long time. Also to be sure this worked with the most recent facebook API I updated to the latest as of this post (Nov 2011 build).
Called from your code:
Facebook API method:
If this helps you please up rate this thread and my post to help others find it.
gadildafissh
恐怕答案是否定的,你不能这样做。
您的应用程序位于沙箱中,无法在外部写入,其中全局cookie(用于移动Safari)和Facebook应用程序设置(我认为在Facebook应用程序首选项/cookies中)
您只能警告您的用户在您的应用程序之外注销。 ..
...或者您可以不使用 facebook api SSO,而是在应用程序登录 Web 表单中使用,就像我出于其他原因所做的那样。
如果您选择该选项此拉取请求可能会节省您一些时间;)
I'm afraid the answer is no, you can't do this.
Your application is in a sandbox, and can't write outside, where global cookies are (for mobile safari) and Facebook app settings (in Facebook app preferences/cookies I think)
You can only warn your user to logout outside of your app...
...Or you can just not use facebook api SSO, but in app login webform, like I do for other reasons.
If you choose that option this pull request might save you some time ;)
Hii,
这是不可能的,原因是单点登录(SSO)并不是让用户每次登录,他都会注销,而是如果用户登录任何启用 FB 的应用程序 - 它将使用它再次登录 - 这是因为该设备主要由单人使用,在这种情况下,只有一个用户可以登录 Facebook。
您无法控制您的应用程序之外的任何应用程序 - 例如 - 如果您使用 Gmail 和 Google 登录当您打开 google.com 时,您可以看到当前登录的用户名具有 SSO,
Hii ,
its not possible , the reason is for Single Sign On (SSO) is not to make user login everytime, he logouts , instead if the user logs in anyone of FB enabled apps - it will use that to login again - This is because the device is mostly used by single person in this case only one user can login in Facebook.
you can't control any app outside of your app - for Example - if u login with Gmail & when you open google.com you can see your username there is currently logged In which has SSO,
在 Facebook 的新 SDK 中,您可以设置登录按钮
loginBehaviour
属性,下面的代码是 swift ...
In new SDK of Facebook, you can set login button
loginBehaviour
propertyBelow code in swift ...
答案已经完成,但我只是想澄清一下。也许它节省了某人的时间。
转到 Facebook.m 并将行更改
为
这将导致登录窗口出现在应用程序内。注销将完美运行。换句话说,它将像在旧版本操作系统中一样工作。
Answer already done, but I just want to clarify it. May be it saved somebody's time.
Go to Facebook.m and change line
to
It will cause login window appear inside the app. Logout will work perfect. In other words, it will work as it used to in older versions of OS.
除了 kishnan94 的答案。 Objective C 版本是;
如果您想要打开一个模式并独立于 Safari 或 Facebook 应用程序请求 facebook 凭据,只需使用最新的 facebook sdk 并设置登录行为,
这将使注销过程更加方便,并且对于不使用 safari 或 facebook 应用程序的用户来说不会那么混乱账户。
in addition to kishnan94 answer. the objective c version is ;
if you want a modal to open up and ask for facebook credentials seperately from Safari or Facebook app, just use the latest facebook sdk and set the login behaviour
this will make the logout process more convenient and less confusing for users without using safari or facebook app accounts.
看来这是Facebook SDK的一个bug。如果设备上安装了 Facebook 应用程序,则更新
access_token
。另一方面,access_token
和expirationDate
无法更改。 :((It seems that this is a bug of Facebook SDK. In a case of the Facebook app is installed on device,
access_token
is renewed. In other hand,access_token
andexpirationDate
could not be changed. :((