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

问题描述 投票:0回答:1

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

{
 "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."
 }
}
  • 该项目是正确的
  • 拥有所有者权利的新服务帐户一直是created
  • 此服务帐户已获得google play console的权利

Documentation在这里说你可以做什么

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

验证网址是正确的,因为如果你得到一个令牌client to server然后这个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'}


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

我期待这个result

更新1

添加tokeninfo

authentication google-oauth2 android-inapp-purchase server-to-server
1个回答
0
投票

我喜欢谷歌。

使用我的第一个服务帐户7天后,它工作了 - 但是7天!!!! 7天 !!!!这太可怕了

在谷歌的人你需要7天才能访问api !! - 这是荒唐的

好的,你需要这样才能获得访问权限

  • 在Google云中创建服务帐户(管理员权限)
  • 创建谷歌播放控制台和链接项目谷歌云
  • 在Google Play控制台中添加电子邮件服务帐户
  • 一周后它会工作
© www.soinside.com 2019 - 2024. All rights reserved.