简体   繁体   English

应用程序购买中的 Android:BillingClient:getPurchase() 失败。 响应码:3

[英]Android in app purchase: BillingClient: getPurchase() failed. Response code: 3

I'm implementing Android in app purchases, with BillingClient api.我在应用程序购买中实施 Android,使用 BillingClient api。

I successfully set up billing client, like this:我成功设置了计费客户端,如下所示:

   billingClient = BillingClient.newBuilder(this)
        .enablePendingPurchases()
        .setListener(this).build()

And I implement the code I want to make the in app purchase, which in my case is a subscription.我实现了我想要进行应用内购买的代码,在我的例子中是订阅。

My issue is as follows, I need to check (periodicly) if the user still has an active subscription, or if they canceled it.我的问题如下,我需要(定期)检查用户是否仍有活动订阅,或者他们是否取消了订阅。 From what I read, I can do a call of the method, queryPurchases(PRODUCT_ID).根据我阅读的内容,我可以调用该方法 queryPurchases(PRODUCT_ID)。 I am doing this as follows:我这样做如下:

 override fun onBillingSetupFinished(billingResult: BillingResult?) {
            if (billingResult != null) {

                if (billingResult.responseCode == BillingClient.BillingResponseCode.OK){

                    // The BillingClient is ready. You can query purchases here.

                    Log.d(TAG_PURCHASES_ACTIVITY, "BillingClient ready and connected")

                    billingClient.queryPurchases(MONTHLY_AGENT_SUBSCRIPTION_PRODUCT_ID)

                }

                else{
                    Log.d(TAG_PURCHASES_ACTIVITY, "BillingClient ERROR: ${billingResult.responseCode}")
                }



            }
        }

However, I get this message in the console:但是,我在控制台中收到此消息:

W/BillingClient: getPurchase() failed. Response code: 3

Now after researching, many have said that this is coming from old phones, with older versions of google play services.现在经过研究,许多人说这是来自旧手机,带有旧版本的 google play 服务。 But I am using new phone (Pixel 3a), which is up to date.但我使用的是最新的新手机(Pixel 3a)。 This phone also has the google account registered in the google play console for testing.这款手机还有在google play console注册的google账号进行测试。

Why I am getting this message?为什么我会收到此消息?

Also, is this really the correct way to check if the subscription is still active?另外,这真的是检查订阅是否仍然有效的正确方法吗?

I've tried for ages to find this solution, thanks for any help!我已经尝试了很长时间才能找到这个解决方案,感谢您的帮助!

I was making a mistake, passing the product id as a parameter to the query request.我犯了一个错误,将产品 ID 作为参数传递给查询请求。 This is what I needed to do:这是我需要做的:

var list = billingClient.queryPurchases(SkuType.SUBS)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM