简体   繁体   English

Android Facebook SDK-如何以其他用户身份登录?

[英]Android Facebook SDK - How to log in as another user?

I am using the official Facebook SDK for Android in my app. 我在我的应用程序中使用的是官方的Android版Facebook SDK。

I have managed to log in successfully, 我已成功登录,
but the problem arises when I try to log in as another user: 但是当我尝试以其他用户身份登录时会出现问题:
I click on the link that says Logged in as [name]... Not you? 我单击显示Logged in as [name]... Not you?的链接Logged in as [name]... Not you?
but my application proceeds anyway and posts to my wall... 但我的申请仍在继续,并贴到我的墙上...
(as if I have clicked "Allow") (就像我点击了“允许”一样)

I discovered that clicking on that link throws a facebook exception and retries the request, 我发现点击该链接会引发Facebook异常并重试该请求,
so I tried putting a call to logout() in the catch clause. 所以我尝试在catch子句中调用logout()。

That made it possible to log in as a new user, 这样就可以以用户身份登录,
but the next time I run the app, 但是下次我运行该应用程序时,
again, the old user is logged-in... 再次, 用户已登录...
(Logged in as [old_user]. Not you?) (以[old_user]登录。不是吗?)


My question is: 我的问题是:
Why does the first user's login persist forever 为什么第一个用户的登录会永久保留
and how to properly handle a click on "Not You" link? 以及如何正确处理“不是您”链接的点击?


My current solution is to always call logout() before authorize() method 我当前的解决方案是始终在authorize()方法之前调用logout()
but this forces the user to always have to enter his/her email/password 但这迫使用户总是必须输入他/她的电子邮件/密码
which is not acceptable either. 这也不可接受。

The facebook access token is saved by SessionStore. Facebook访问令牌由SessionStore保存。 When loggin into Facebook, it will try to restore the access token from SessionStore. 登录Facebook时,它将尝试从SessionStore恢复访问令牌。 So, I think you can explicitly call facebook.logout and SessionStore.clear() when user exit your application. 因此,我认为您可以在用户退出应用程序时显式调用facebook.logout和SessionStore.clear()。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM