Android发布商权限被拒绝仅检查付款(其他api成功)

Yar*_*lyk 3 authentication server-to-server google-oauth android-inapp-purchase

我正在尝试调用 api Purchases.products: get来验证您的购买,它会产生这样的结果

{
 "error": {
  "errors": [
   {
    "domain": "androidpublisher",
    "reason": "permissionDenied",
    "message": "The current user has insufficient permissions to perform the requested operation."
   }
  ],
  "code": 401,
  "message": "The current user has insufficient permissions to perform the requested operation."
 }
}
Run Code Online (Sandbox Code Playgroud)

这里的文档说明了你可以做什么

收到的令牌不仅仅适用于任何其他 api 的购买检查,它返回结果(Inappproducts: list is work

验证 url 构建正确,因为如果您将令牌客户端连接到服务器,那么此 api 也可以工作 - 但我需要一个服务器来进行服务器身份验证

scopes =  ['https://www.googleapis.com/auth/androidpublisher']
authorization = Google::Auth.get_application_default(scopes)

uri = "https://www.googleapis.com/androidpublisher/v3/applications/#{ENV['ANDROID_PACKAGE_NAME']}/purchases/products/#{purchasable.purchase_uuid}/tokens/#{purchase_token}?access_token=#{authorization.fetch_access_token!['access_token']}"

response = RestClient::Request.execute method: :get,
                                           url: uri,
                                           headers: {'Content-Type':'application/json'}

Run Code Online (Sandbox Code Playgroud)


file = File.read('config/google_key.json')
values = JSON.parse(file)


oauth = Signet::OAuth2::Client.new(
          issuer:               values[:client_email]",
          audience:             "https://www.googleapis.com/oauth2/v4/token",
          scope:                "https://www.googleapis.com/auth/androidpublisher",
          client_id:            values[:client_id],
          signing_key:          OpenSSL::PKey::RSA.new(values[:private_key]),
      )

      jwt = oauth.to_jwt

      url = "https://www.googleapis.com/oauth2/v4/token"
      begin
        response = RestClient::Request.execute method: :post,
                                               url: url,
                                               headers: {'Content-Type': 'application/json'},
                                               payload: {
                                                   grant_type: "urn:ietf:params:oauth:grant-type:jwt-bearer",
                                                   assertion: jwt
                                               }

        result =  JSON.parse response.body
      rescue => e
        puts e.response.to_str
        result =  JSON.parse(e.response.to_s)
      end
Run Code Online (Sandbox Code Playgroud)

我期待这个结果

更新1

添加代币信息

Yar*_*lyk 5

我喜欢谷歌。

使用我的第一个服务帐户 7 天后,它起作用了 - 但是 7 天!!!7天 !!!!这只是恐怖

Google 的朋友们,你们需要 7 天才能访问 api!- 这是荒唐的

好的,您需要执行此操作才能访问

  • 在谷歌云中创建服务帐户(管理员权限)
  • 创建 google play console 并链接项目 google cloud
  • 在 Google Play 控制台中添加电子邮件服务帐户
  • 1周后就会起作用

  • @DataGreed嗨,这是一个问题在7天后自动解决))我认为GCP需要时间来共享访问权限。我的建议是再次检查所有内容,如果一切正常,则等待几天。如果问题明天就会出现,您可以尝试创建新的凭据,然后再等待 2 天。您将创建临时[决策](https://developers.google.com/android-publisher/authorization),当 сredentials 起作用时,您将替换临时决策 (2认同)