简体   繁体   English

Android Facebook和Google+离线登录

[英]Android Facebook and Google+ offline login

My android application requires the user to login using Facebook or Google+ to see the contents of the app. 我的Android应用程序要求用户使用Facebook或Google+登录才能查看应用程序的内容。

When the user is always connected to the internet everything works fine, i get the access token for the service he chose and life is good. 当用户始终连接到Internet时,一切正常,我会获得他选择的服务的访问令牌,生活会很好。

The thing is, i want the user to be able to auto-login without internet connection, using the last user he went online with. 问题是,我希望该用户能够使用与其上次上网的最后一个用户,而无需互联网连接即可自动登录。 I have the last access token stored in a file, but i don't know what to do with it to make my app have that behaviour. 我拥有文件中存储的最后一个访问令牌,但是我不知道该如何处理才能使我的应用程序具有这种行为。

The access token you have stored in a file signifies two things: 您存储在文件中的访问令牌表示两件事:

  1. The associated Android account was authenticated as a particular Google+/Facebook user ID. 关联的Android帐户已通过身份验证,成为特定的Google + / Facebook用户ID。
  2. The user has granted your app permission to make certain queries against Google+/Facebook APIs on their behalf. 用户已授予您的应用权限,代表他们对Google + / Facebook API进行某些查询。

The first part is valid regardless of whether you have an internet connection. 无论您是否有互联网连接,第一部分均有效。 As long as the associated Android account still exists on the device then you have an authenticated identity for the user. 只要关联的Android帐户仍存在于设备上,您便拥有该用户的身份验证身份。 So you don't need to do anything specific with the access token, you can simply store the Android account that it is associated with and display the offline experience for that user. 因此,您不需要对访问令牌进行任何特定的操作,只需存储与之关联的Android帐户并显示该用户的离线体验即可。

The second part clearly won't work without an internet connection. 如果没有互联网连接,第二部分显然将无法工作。 So you will not be able to establish a connected PlusClient or Session object while the user has no internet connection. 因此,当用户没有Internet连接时,您将无法建立连接的PlusClient或Session对象。

You might notice that the user has no internet, and then not show the login activity. 您可能会注意到用户没有互联网,然后没有显示登录活动。 then if there's any info that you want to associate with what ever account they last logged in with, you will need your own data store to cache it in, so that you can sync it next time you notice they have internet. 然后,如果您有任何信息要与他们上次登录的帐户相关联,则需要使用自己的数据存储区对其进行缓存,以便下次发现他们可以连接互联网时进行同步。

See the similar question: https://stackoverflow.com/a/16538254/1449799 看到类似的问题: https : //stackoverflow.com/a/16538254/1449799

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

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