且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

谷歌播放服务SDK:请求的身份验证过程中离线访问

更新时间:2023-12-03 11:09:04

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

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.