You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

React Native项目Google IAP订阅后端验证遇subscriptionInvalidArgument错误

Google IAP订阅后端验证失败问题排查

我的React Native项目前端已实现Google IAP订阅功能,但后端使用gem 'google-api-client'验证订阅时失败,报错:subscriptionInvalidArgument: Your request is invalid for this subscription purchase. (Google::Apis::ClientError)。当前应用处于内部测试阶段,仅需验证Google IAP订阅,以下是我的后端代码、调用示例及错误输出,请求排查是否存在明显问题:

后端代码

require 'google/apis/androidpublisher_v3'

class GooglePlayService
  def initialize(package_name, purchase_token, product_id)
    @package_name = package_name
    @purchase_token = purchase_token
    @product_id = product_id
    @android_publisher = Google::Apis::AndroidpublisherV3::AndroidPublisherService.new
    @android_publisher.authorization = authorize
  end

  def authorize
    key_file_path = Rails.root.join('config', 'keys', 'google', 'xxxxx.json')
    json_key = File.read(key_file_path)

    Google::Auth::ServiceAccountCredentials.make_creds(
      json_key_io: StringIO.new(json_key),
      scope: 'https://www.googleapis.com/auth/androidpublisher'
    )
  end

  def query_subscription
    @android_publisher.get_purchase_subscription(
      @package_name,
      @product_id,
      @purchase_token
    )
  end

  def query_product
    @android_publisher.get_purchase_product(
      @package_name,
      @product_id,
      @purchase_token
    )
  end
end

调用示例

service = GooglePlayService.new('com.xxx.xxx', 'hmgccjeedhfjbahhbcinbjbo.AO-J1OxSl_Ir1YnoodqVDcXIJWopC-v1NgYKZZhVrr6l4qQ78tjKWPG_LDhViph-pniR83SjE8VmqJr-60VhZV5nPAndhxUSCw', 'weekly_subscription_3')

service.query_subscription

错误输出

["Content-Type", "application/json; charset=UTF-8"], ["Content-Encoding", "gzip"], ["Date", "Wed, 17 May 2023 00:27:43 GMT"], ["Server", "ESF"], ["Cache-Control", "private"], ["X-XSS-Protection", "0"], ["X-Frame-Options", "SAMEORIGIN"], ["X-Content-Type-Options", "nosniff"], ["Alt-Svc", "h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000"], ["Transfer-Encoding", "chunked"]], @dumped=false> body: "{
  \"error\": {
    \"code\": 400,
    \"message\": \"Your request is invalid for this subscription purchase.\",
    \"errors\": [
      {
        \"message\": \"Your request is invalid for this subscription purchase.\",
        \"domain\": \"androidpublisher\",
        \"reason\": \"subscriptionInvalidArgument\"
      }
    ]
  }
}
">

/home/noobskie/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/google-apis-core-0.11.0/lib/google/apis/core/http_command.rb:239:in `check_status': subscriptionInvalidArgument: Your request is invalid for this subscription purchase. (Google::Apis::ClientError)

内容的提问来源于stack exchange,提问作者NooBskie

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.21 14:57:46