从多个活动访问 google plus 客户端 [英] Access google plus client from multiple activities

查看:24
本文介绍了从多个活动访问 google plus 客户端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个应用程序,其中集成了 google plus.到目前为止它工作正常,我能够检索用户配置文件.

I'm developing an application in which i have integrated google plus. So far Its working fine, I am able to retrieve the user profile.

但现在我想做以下事情:

But now i want to do the following:

1) 我有两个活动 signInActivityshareActivity.

1)I have two activity signInActivity and shareActivity.

2)如果用户已经使用 signInActivity 登录,则不应再次要求登录shareActivity 并且应该直接分享内容.

2)If user is already signin using signInActivity then it should not ask for signin again in shareActivity and should directly share the content.

3)如果用户未在 signInActivity 中登录并尝试使用 shareActivity 共享数据,则应用应登录用户,然后仅共享数据.在这种情况下,如果用户返回到 signInActivity 然后应用程序应该显示你已经登录"

3)If user is not signedin in the signInActivity and try to share data using shareActivitythen app should signin the user and then only share the data. In this case if user goes back to the signInActivity then app should show that "you have already signedin"

简而言之,我希望用户登录在应用程序中中央,这样如果它已经登录,它应该可以从任何活动中访问.

In short i want user signin to be Central within application so that if it is alrady signedin it should be accessible from any activity.

我听说过访问令牌,但我不知道如何使用它,而且文档说它会在一小时后过期,这不是我想要的.

I have heard about the access token but i dont know how to use it and document says that it expires in an hour which is not what i want.

我怎样才能让中央谷歌加号登录?是否可以?或者我需要在每个活动中对用户进行身份验证?

How can i make central google plus signin? is it possible? or i need to authenticate user in each activity?

推荐答案

在每个 Activity 中管理单独的 GoogleApiClient 实例不会导致用户被要求多次登录.

Managing a separate instance of GoogleApiClient in each activity will not result in the user being asked to sign in multiple times.

Google+ 登录(即 GoogleApiClient)为设备上的 Google 帐户和 Google Play 服务核心服务提供了一个接口 - 它没有每个 GoogleApiClient 实例的状态.因此,一旦您的应用程序的设备帐户通过身份验证,GoogleApiClient 的新实例将访问相同的状态.GoogleApiClient 专门设计为一种轻量级的方式来访问由 Google Play 服务管理的中央状态.

Google+ Sign-in (ie. GoogleApiClient) provides an interface to the Google accounts on the device and the Google Play services core service - it doesn't have state per GoogleApiClient instance. So once a device account has been authenticated for your app, new instances of GoogleApiClient will access the same state. GoogleApiClient is specifically designed to be a lightweight way to access the central state managed by Google Play services.

您在访问令牌方面很幸运!Google Play 服务会为您处理所有令牌管理.因此,尽管访问令牌仅持续一小时,如您所说,如果您尝试使用 PlusClient 访问 Google API 并且您的访问令牌已过期,Google Play 服务将透明地为您请求新的访问令牌并完成调用.

You're in luck regarding access tokens! Google Play services takes care of all token management for you. So although access tokens only last for one hour, as you say, if you try to use your PlusClient to access a Google API and your access token has expired, Google Play services will transparently request a new access token for you and complete the call.

有关更多详细信息,请查看此 Google I/O 演讲的第一部分:

Take a look at the first part of this Google I/O talk for more details:

http://www.youtube.com/watch?v=_KBHf1EODuk

这篇关于从多个活动访问 google plus 客户端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆