Console后台配置
配置流程如下:
- 创建OAuth client
- 创建的时候选择Web application
- Authorized redirect URIs,需要填写,后面会用到,随便填一个,后面可以修改
- OAuth consent screen 的Test Users中添加Google Play Console账户
创建Service accounts设置Acess里设置,App permissions中添加对应的App,Access permissions中勾选Manage orders and subscriptions
![](https://img-blog.csdnimg.cn/c2ff5702e10048558e029b672fee8fc1.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBAZHJpZnRib2F0,size_20,color_FFFFFF,t_70,g_se,x_16)
获取Token和RefreshToken
- 用浏览器打开以下地址,用上面Test Users中添加Google Play Console账户登录,获取code(redirect_uri为上面的1-2部分),参数重定向到您的重定向 URI,该参数类似于
4/eWdxD7b-YSQ5CNNb-c2iI83KQx19.wp6198ti5Zc7dJ3UXOl0T3aRLxQmbwI
。
https://accounts.google.com/o/oauth2/auth?scope=https://www.googleapis.com/auth/androidpublisher&response_type=code&access_type=offline&redirect_uri=...&client_id=...
-
用PostMan,获取Token和RefreshToken,注意保存好RefreshToken![](https://img-blog.csdnimg.cn/5939b29518354f3a925c5913d15d729d.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBAZHJpZnRib2F0,size_20,color_FFFFFF,t_70,g_se,x_16)
-
用Curl命令测试acknowledge,红色部分需要替换
curl --request POST \
'https://androidpublisher.googleapis.com/androidpublisher/v3/applications/packageName/purchases/products/productId/tokens/inapptoken:acknowledge' \
--header 'Authorization: Bearer Token' \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--data '{}' \
--compressed
如果收到400错误,表示购买过期了,如果是测试账户购买5分钟后过期,如果没有acknowledge,会收到退款消息,如果正式账户购买3天后过期
刷新Token
![](https://img-blog.csdnimg.cn/50b30823ec254b65b05d451db4b0adf3.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBAZHJpZnRib2F0,size_20,color_FFFFFF,t_70,g_se,x_16)
问题及解决方法
Refresh Token过期问题
用了一段时间发现,每隔一周,RefreshToken就失效了,查阅了资料,要在同意屏幕页面将状态变为发布状态(或者尝试用jwt-bear的方式获取Token:https://developers.google.com/identity/protocols/oauth2/service-account
https://blog.frost.tw/posts/2019/12/29/How-to-use-Service-Account-to-exchange-Google-OAuth2-API-token/
)
https://developers.google.com/identity/protocols/oauth2#expiration
A Google Cloud Platform project with an OAuth consent screen configured for an external user type and a publishing status of "Testing" is issued a refresh token expiring in 7 days.
Malformed auth code
dhttps://www.urldecoder.org/ 将code解码
无Refresh Token
只有第一次授权才会有RefreshToken,到以下地方删除授权,重新获取
https://myaccount.google.com/u/0/permissions
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)