首页 > 解决方案 > Google Play 开发者 API 未返回刷新令牌

问题描述

我想使用Purchase.Subscription API 获取订阅数据。为此,我试图从https://accounts.google.com/o/oauth2/token获取令牌。

根据文档,它应该返回我以下响应:

{
  "access_token" : "ya29.ZStBkRnGyZ2mUYOLgls7QVBxOg82XhBCFo8UIT5gM",
  "token_type" : "Bearer",
  "expires_in" : 3600,
  "refresh_token" : "1/zaaHNytlC3SEBX7F2cfrHcqJEa3KoAHYeXES6nmho"
}

但是当我尝试遵循相同的步骤时,我没有得到refresh_token字段作为响应。如文档中所述,我正在发送以下字段:

grant_type=authorization_code
code=<the code from the previous step>
client_id=<the client ID token created in the APIs Console>
client_secret=<the client secret corresponding to the client ID>
redirect_uri=<the URI registered with the client ID>

请帮助我我所缺少的。

标签: androidgoogle-playgoogle-play-developer-api

解决方案


好的。我发现了实际问题。这在 API 方面确实缺乏文档。在允许应用管理您的开发者帐户后,我们将仅在第一次使用以下数据调用 api https://accounts.google.com/o/oauth2/token时获得 refresh_token 值:

grant_type=authorization_code
code=<the code from the previous step>
client_id=<the client ID token created in the APIs Console>
client_secret=<the client secret corresponding to the client ID>
redirect_uri=<the URI registered with the client ID>

如果您没有获得 refresh_token,您可以按照此答案中提到的步骤尝试再次获取 refresh_token


推荐阅读