- 到Google Play Console 登录开发者账号, 用 Owner 账号
- Setting -> Developer account -> API access 找到Service Accounts(没有Service Accounts的话,创建一个即可
- 点击 View In Google Developer Console跳转到Console后台
- 创建Credentials web application生成Client ID 和 Client Secret
- 参考 https://developers.google.com/android-publisher/authorization 生成refresh_token
- 理论上一个GooglePlay开发者账号创建一套Client ID参数即可
生成refresh_token 步骤:
2. 请求地址后需要输入登陆账号,登录Owner账号(应该登陆服务账号也可以),登陆完成后将浏览器地址栏的地址复制出来,如:https://xxx.xxx.com/?code=4/0AX4XfWj-pzsABnvgQve51vVWJKC9N99d5Q4ReM6OXUYNas8pow2Ts1KDqR6qfY-MFPU8dQ&scope=https://www.googleapis.com/auth/androidpublisher
3. 找到地址中的 code 参数,注意:参数有效期很短,如果失效后重复步骤1,在示例中参数为:4/0AX4XfWj-pzsABnvgQve51vVWJKC9N99d5Q4ReM6OXUYNas8pow2Ts1KDqR6qfY-MFPU8dQ
4.向 https://accounts.google.com/o/oauth2/token发送post请求,请求 携带参数:
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>
在示例中:
curl -X POST -d 'grant_type=authorization_code&code=$(code)&client_id=${client_id}&client_secret=${client_secret}&redirect_uri=${redirect_uri}' https://accounts.google.com/o/oauth2/token
或用请求工具:
请求成功后即可获取 refresh_token