简体   繁体   English

在Android中登录Google+,然后维护离线会话

[英]Google+ login in android and then maintain offline session

Scope 范围

I want to have google login in my app. 我想在我的应用中使用google登录。 For this I referred to https://developers.google.com/+/mobile/android/sign-in and was able to create a basic login. 为此,我提到了https://developers.google.com/+/mobile/android/sign-in并能够创建基本登录名。

Problem 问题

Now, the problem is quite interesting. 现在,这个问题很有趣。 The login process works like a charm, but only when internet is connected. 登录过程就像一个超级按钮一样工作,但仅在连接互联网时才起作用。 Lets get to a specific use case: 让我们进入一个特定的用例:

  1. I started the app, logged in with my xxxx@gmail.com. 我启动了该应用程序,并使用我的xxxx@gmail.com登录。
  2. I closed the app, started again. 我关闭了应用程序,然后再次启动。 It automatically logs in to xxxx@gmail.com. 它会自动登录到xxxx@gmail.com。 Technically: onConnected() gets called. 从技术上讲:onConnected()被调用。 (It has to be like this, no problem) (必须是这样,没问题)
  3. I closed the app, and turned off the internet connectivity. 我关闭了应用程序,并关闭了互联网连接。
  4. Now again started the app the account gets logged out as I can see in logs: 'clearing selected account for *packagename' - (something related to this) 现在再次启动该应用程序,该帐户已注销,正如我在日志中看到的那样:“清除* packagename的选定帐户”-(与此相关的内容)
  5. I again switched on the internet connectivity and then started the app, nothing happens. 我再次打开互联网连接,然后启动了该应用程序,什么也没发生。 It(the account) doesnt gets logged in (since it was logged out automatically). 它(帐户)没有登录(因为它是自动注销的)。 Technically: this time onConnectionFailed() gets called 技术上:这次onConnectionFailed()被调用

So, I want to keep this login even if the internet is switched off, what can I do? 因此,即使互联网已关闭,我也要保留此登录名,该怎么办? A couple of other apps do this stuff. 其他几个应用程序也可以做到这一点。

Self Digging 自挖

  1. I went through the logs of other popular apps having google Login, and in which the login persists even if the internet is not connected and compared those logs with that of my apps' logs. 我浏览了其他具有google Login的流行应用程序的日志,即使互联网未连接,该登录仍然存在,并将这些日志与我的应用程序的日志进行了比较。

Logs in Other apps: 登录其他应用程序:

  02-16 00:51:13.493: W/GLSUser(26959): [GLSUser] [GLSUser]  Permission for *packagename* to access oauth2:https://www.googleapis.com/auth/userinfo.email will be managed locally.

Logs in My apps: 登录我的应用程序:

   02-16 00:50:16.203: W/GLSUser(26959): [GLSUser] [GLSUser]  Permission for *packagename* to access oauth2:https://www.googleapis.com/auth/plus.me will be managed remotely.
  1. I found that this weird thing happens only when I am using scope = 我发现只有在我使用scope =时才会发生这种奇怪的事情

     Plus.SCOPE_PLUS_PROFILE 

    However, when I use scope = 'email' or 'profile' or Plus.SCOPE_PLUS_LOGIN. 但是,当我使用scope ='email'或'profile'或Plus.SCOPE_PLUS_LOGIN时。 It works fine in offline mode. 在离线模式下可以正常工作。

Can anybody help me ?? 有谁能够帮助我 ??

Most probably you are not storing the credentials (the Auth Token) and using it to re-authenticate on resume. 您很可能没有存储凭据(身份验证令牌),而是使用它在简历上重新进行身份验证。

Check this sample from the Google API client for java. 从Java的Google API客户端检查示例。

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

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