天天看点

配置Google支付相关参数(client_id, client_secret, refresh_token)

  • 1. 登陆Google开发者账号,点击左边API权限

    Google控制台
    配置Google支付相关参数(client_id, client_secret, refresh_token)

创建新项目

  1. 转到 Google Play 管理中心的 API 权限页面。
  2. 接受《服务条款》。
  3. 点击创建新项目。
系统会自动生成 Google Cloud 项目,并将其关联到您的 Google Play 管理中心。
  • 2. 配置服务账号

    • 转到 Google Play 管理中心的 API 权限页面,点击服务帐号下的创建新的服务帐号。
      配置Google支付相关参数(client_id, client_secret, refresh_token)
    • 在创建帐号的过程中,您需要向自己的服务帐号授予对 Cloud 项目的访问权限,这样它才能显示在 Google Play 管理中心内。
      配置Google支付相关参数(client_id, client_secret, refresh_token)
    • 点击Google cloud platform创建,先将Google play项目和自动创建的cloud platform项目绑定
      配置Google支付相关参数(client_id, client_secret, refresh_token)
    • 然后点击创建服务账号
      配置Google支付相关参数(client_id, client_secret, refresh_token)
      填入名称即可,其他都是可选。
    • 完成后可以下载密钥保管到电脑上
      配置Google支付相关参数(client_id, client_secret, refresh_token)
    • 在 Google Play 管理中心创建服务帐号后,点击完成。API 权限页面的“服务帐号”部分会自动刷新,您的服务帐号将随即列出。
      配置Google支付相关参数(client_id, client_secret, refresh_token)
    • 点击授予访问权,为服务帐号提供执行相关操作所需的权限。此时,您应该能够通过服务帐号访问 Google Play Developer API。如需了解详情,请参阅针对服务器对服务器应用使用 OAuth 2.0。
  • 3. 创建OAuth客户端

    • 在创建 OAuth 客户端之前,您需要为产品配置品牌信息。
    • 转到 Google Play 管理中心的 API 权限页面。点击 OAuth 客户端下的配置 OAuth 权限请求页面。由于我已经配置了相关信息,这里就没有显示配置客户端而是创建客户端。
      配置Google支付相关参数(client_id, client_secret, refresh_token)
    • 配置产品的品牌信息。完成配置后,点击刷新 OAuth 权限请求信息。此部分会相应更新,您不会再看到与品牌信息有关的消息。
    • 然后再创建客户端
      • 创建好了之后查看客户端id和客户端密钥即client_id和client_secret
      配置Google支付相关参数(client_id, client_secret, refresh_token)
      • 其中的重定向url可以问后端要
    • 在 Google Play 管理中心创建 OAuth 客户端后,点击完成。API 权限页面的 OAuth 客户端部分会自动刷新,您的 OAuth 客户端将随即列出。
    • 有时新的 OAuth 客户端不会立即显示在页面上。在这种情况下,请点击刷新 OAuth 客户端。新 OAuth 客户端的详细信息会以列表形式显示在此页面上。
  • 4. 获取您的开发者 ID

    • 有些 API 需要您提供 Google Play 管理中心开发者 ID。这是在创建您的 Google Play 开发者帐号时分配的一个长号码。您可以在 Google Play 管理中心内几乎任何页面(例如 API 权限页面)的网址中找到您的开发者 ID。
    • 以 Google Play 管理中心的网址为例:
      https://play.google.com/console/developers/1234567890123456789/api-access
                 
    • 在以上网址中,开发者 ID 为

      1234567890123456789

      注意:当应用从一个 Google Play 开发者帐号转移到另一个 Google Play 开发者帐号时,与该应用关联的开发者 ID 将会发生变化。这意味着,转移完成后,在该应用的 API 调用中,您将必须使用新的 Google Play 开发者帐号的开发者 ID。

  • 5. 生成刷新令牌(refresh_token)

    • 先使用你的Google play账号登陆后,转到以下uri:
      https://accounts.google.com/o/oauth2/auth?scope=https://www.googleapis.com/auth/androidpublisher&response_type=code&access_type=offline&redirect_uri=...&client_id=...
                 
    • 将上一步填写的重定向uri和client_id填入

      注意:

      redirect_uri

      参数必须与使用客户端 ID 注册的值完全匹配,包括末尾的反斜杠(如果有)。
    • 看到系统提示时,请选择允许访问。
      • 如果有多个账号,选择你的开发者账号
      配置Google支付相关参数(client_id, client_secret, refresh_token)
    • 浏览器将使用

      code

      参数重定向到您的重定向 URI,该参数类似于

      4/eWdxD7b-YSQ5CNNb-c2iI83KQx19.wp6198ti5Zc7dJ3UXOl0T3aRLxQmbwI

    • 在之后的uri中找到code

      https://类似于/?code=4%2F0AX4XfWicL_0-Q_jdsl_zrX0KfByRhXwOUrHYaY6XbtvQZoswf_Z1CBRzvXgCl9e-RfybZQ&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fandroidpublisher#/login?redirect=%2Fdashboard

    • 将该代码替换为访问权限和刷新令牌组合,为此,您需要向

      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>
                 
    • 然后使用postman
      配置Google支付相关参数(client_id, client_secret, refresh_token)
    • 成功响应后,获得refresh_token
      {
        "access_token" : "ya29.ZStBkRnGyZ2mUYOLgls7QVBxOg82XhBCFo8UIT5gM",
        "token_type" : "Bearer",
        "expires_in" : 3600,
        "refresh_token" : "1/zaaHNytlC3SEBX7F2cfrHcqJEa3KoAHYeXES6nmho"
      }
                 
    • 注意,只有第一次请求会返回refresh_token,请妥善保管

      然后,在后台将内购所需要的client_id,client_secret,refresh_token一一配置,大功告成~

  • 参考文章

    https://blog.csdn.net/chenglinlin526/article/details/78086127

    https://developers.google.com/android-publisher/getting_started?hl=zh-cn

    https://developers.google.com/android-publisher/authorization

继续阅读