mService.consumePurchase(3,的packageName,purchaseToken)总是返回RESULT_DEVELOPER_ERROR = 5 - 提供给API的参数无效 [英] mService.consumePurchase(3, packageName, purchaseToken) always returns RESULT_DEVELOPER_ERROR = 5 - invalid arguments provided to the API

查看:838
本文介绍了mService.consumePurchase(3,的packageName,purchaseToken)总是返回RESULT_DEVELOPER_ERROR = 5 - 提供给API的参数无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我总是得到RESULT_DEVELOPER_ERROR = 5 - 提供的API无效的参数,试图消耗与

购买时,

 字符串purchaseToken =inapp:+ getPackageName()+:+ productId参数;
INT响应= 0;
尝试 {
    响应= mService.consumePurchase(3,getPackageName(),purchaseToken);
}赶上(RemoteException的E){
    // TODO自动生成的catch块
    e.printStackTrace();
}
 

出于这个原因,我总是可以只进行购买一次。然而,我需要能够进行购买更经常。我一直在试图解决这个问题,2天了,没有成功。 :/

制作和购买消费与SKUandroid.test.purchased工作完全正常,但是当我出口与生产骨干的.apk文件,并添加在线SKU,购买只显示一次,然后永远不再。

下面一些细节

  1. 的.apk文件Play商店,我用我的手机上导出.apk文件的版本code相同,并使用相同的密钥库签署
  2. 我已经试过了对托管和非托管的产品,但是这不应该的问题,因为的根据最新应用内结算文档,托管和非托管被视为管理的产品,都有被消耗
  3. 在我只有5 SKU项目,所以它不打20的限制,这是问题的here
解决方案

购买令牌从SKU本身不同的,相反,你应该检索 purchaseToken 通过code,如:

  //注意空是continueToken你可能无法获得全部的购买的物品
//在一个调用 - 检查ownedItems.getString(INAPP_CONTINUATION_TOKEN)的
//下面continueToken并重新调用与之前你没有得到令牌
捆绑ownedItems = service.getPurchases(3,getPackageName(),inapp,NULL);
//检查响应
INT响应code = ownedItems.getInt(RESPONSE_ code);
如果(响应code!= 0){
   抛出新的异常(错误);
}
//获取购买的物品清单
ArrayList的<字符串> purchaseDataList =
    ownedItems.getStringArrayList(INAPP_PURCHASE_DATA_LIST);
对于(字符串购买数据:purchaseDataList){
    JSONObject的O =新的JSONObject(购买数据);
    字符串purchaseToken = o.optString(令牌,o.optString(purchaseToken));
    //消费purchaseToken,处理任何错误
    mService.consumePurchase(3,getPackageName(),purchaseToken);
}
 

I'm always getting "RESULT_DEVELOPER_ERROR = 5 - invalid arguments provided to the API", when trying to consume a purchase with

String purchaseToken = "inapp:" + getPackageName() + ":" + productId;
int response = 0;
try {
    response = mService.consumePurchase(3, getPackageName(), purchaseToken);
} catch (RemoteException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}

For that reason, I can always only make a purchase once. However, I need to be able to make the purchase much more often. I've been trying to fix this problem for 2 days now, no success. :/

Making and consuming purchases with SKU "android.test.purchased" works completely fine, however as soon as I export the .apk with the production key and add a live SKU, the purchase only shows up once and then never again.

Here some more details

  1. The version code of the .apk in the play store and the exported .apk I'm using on my phone are the same and were signed with the same keystore
  2. I've tried it for both managed and unmanaged products, however that shouldn't matter, because according to the latest in-app billing documentation, managed and unmanaged are treated as managed products and both have to be consumed
  3. I only have 5 SKU items, so it doesn't hit the limit of 20, which was the problem here

解决方案

The purchase token is different from the SKU itself, instead, you should retrieve the purchaseToken via code such as:

// Note the null is the continueToken you may not get all of the purchased items
// in one call - check ownedItems.getString("INAPP_CONTINUATION_TOKEN") for 
// the next continueToken and re-call with that until you don't get a token
Bundle ownedItems = service.getPurchases(3, getPackageName(), "inapp", null);
// Check response
int responseCode = ownedItems.getInt("RESPONSE_CODE");
if (responseCode != 0) {
   throw new Exception("Error");
}
// Get the list of purchased items
ArrayList<String> purchaseDataList = 
    ownedItems.getStringArrayList("INAPP_PURCHASE_DATA_LIST");
for (String purchaseData : purchaseDataList) {
    JSONObject o = new JSONObject(purchaseData);
    String purchaseToken = o.optString("token", o.optString("purchaseToken"));
    // Consume purchaseToken, handling any errors
    mService.consumePurchase(3, getPackageName(), purchaseToken);
}

这篇关于mService.consumePurchase(3,的packageName,purchaseToken)总是返回RESULT_DEVELOPER_ERROR = 5 - 提供给API的参数无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆