谷歌播放服务SDK:请求的身份验证过程中离线访问 [英] Google play services sdk: Requesting for offline access during auth

查看:291
本文介绍了谷歌播放服务SDK:请求的身份验证过程中离线访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法来请求使用谷歌播放服务SDK在Android离线访问?我知道,href="https://developers.google.com/android-publisher/authorization" rel="nofollow">原始HTTP API 的谷歌播放服务SDK 。

Is there a way to request for offline access using the Google play services sdk on android? I know that the raw HTTP api has an option to do this by requesting for a refresh token, but couldn't find a way to do it via the new Google Play services sdk.

新的SDK提供了应用程序使用 GoogleAuthUtil.getToken()方法的访问令牌,但每隔一小时的访问令牌到期。我可以让原始的HTTP请求,并让用户从Web视图或浏览器登录,但将preFER的方式本身使用SDK做到这一点,因为这是为用户带来更好的体验。

The new sdk gives the app an access token using the GoogleAuthUtil.getToken() method, but the access token expires every hour. I could make the raw http request and have the user sign in from a web view or the browser, but would prefer a way to do it natively using the sdk, since that is a much better experience for the user.

推荐答案

在搜索的谷歌文档近及远,它看起来像,这是可能的。谷歌称此为跨客户端的身份在其混合应用程序类别。

Searching the Google docs near and far, it does look like that this is possible. Google calls this "Cross-client Identity" under its "Hybrid Apps" category.

您可以明显地按摩字符串传递到 GoogleAuthUtil.getToken(...)方法的范围参数哄成返回一个授权code 而不是OAuth2令牌。 (对于它们之间的区别,我发现这个图表的帮助。)

You can apparently massage the string for the scope parameter you pass into GoogleAuthUtil.getToken(...) method to coax it into returning an "Authorization Code" rather than an OAuth2 Token. (For the difference between these, I've found this chart helpful.)

详细是这里,特别是最后一节的Android应用程序获取离线访问的Web后端

The details are here, specifically the last section titled "Android app obtains offline access for Web back-end".

看来你需要通过以下的范围字符串为gettoken:

It seems you'll need to pass in the following as "scope" string to getToken:

oauth2:server:client_id:<your_server_client_id>:api_scope:<scope_url_1> <scope_url_2> ...

该文档,然后声称这样的:

The doc then claims this:

在这种情况下,GoogleAuthUtil.getToken()将首先要求该   用户已经授权该项目用于访问两个作用域。   假设这是确定的,它会返回,而不是OAuth的令牌,但   短暂的授权code,它可以为接入交换   令牌和刷新令牌。

In this case, GoogleAuthUtil.getToken() will first require that the user has authorized this Project for access to the two scopes. Assuming this is OK, it will return, not an OAuth token, but a short-lived authorization code, which can be exchanged for an access token and a refresh token.

免责声明:我没有尝试过这个自己还没有;我们的Andr​​oid开发人员将很快。请报告,如果这是为你工作。

Disclaimer: I've not tried this myself yet; our Android developer will shortly. Please report if this is working for you.

这篇关于谷歌播放服务SDK:请求的身份验证过程中离线访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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