Google的IAB API3 getSkuDetails()方法返回失败5:Developer Error

时间:2013-12-31 19:19:15

标签: android eclipse in-app-purchase in-app-billing

我正在尝试将Google的应用内结算API3合并到我使用API​​2的代码中。

我对mHelper(IabHelper对象)的调用成功,所以我连接到Google的服务器。看来我可以确定自有项目,因为我的QueryInventoryFinishedListener返回一个包含我所有购买项目的有效库存。我也可以执行购买。

但是,查询sku详细信息失败(getSkuDetails())。以下是Eclipse中与IabHelper相关的所有LogCat输出(我删除了我的软件包名称和产品SKU),导致失败:

12-31 11:47:04.642: D/IabHelper(13633): Starting in-app billing setup.
12-31 11:47:04.832: D/IabHelper(13633): Billing service connected.
12-31 11:47:04.832: D/IabHelper(13633): Checking for in-app billing 3 support.
12-31 11:47:04.832: D/IabHelper(13633): In-app billing version 3 supported for com.XXXX.XXXX
12-31 11:47:04.832: D/IabHelper(13633): Subscriptions AVAILABLE.
12-31 11:47:04.842: D/IabHelper(13633): Starting async operation: refresh inventory
12-31 11:47:04.842: D/IabHelper(13633): Querying owned items, item type: inapp
12-31 11:47:04.842: D/IabHelper(13633): Package name: com.XXXX.XXXX
12-31 11:47:04.842: D/IabHelper(13633): Calling getPurchases with continuation token: null
12-31 11:47:04.912: D/IabHelper(13633): Owned items response: 0
12-31 11:47:04.912: D/IabHelper(13633): Sku is owned: com.XXXX.XXXX.item_one
12-31 11:47:04.922: D/IabHelper(13633): Sku is owned: com.XXXX.XXXX.item_two
...
(and 45 other items)
...
12-31 11:47:05.012: D/IabHelper(13633): Continuation token: null
12-31 11:47:05.012: D/IabHelper(13633): Querying SKU details.
12-31 11:47:05.012: D/IabHelper(13633): getSkuDetails() failed: 5:Developer Error
12-31 11:47:05.012: D/IabHelper(13633): Ending async operation: refresh inventory

这似乎不是签名问题,因为我可以成功连接并进行购买。

还有其他人遇到过getSkuDetails()因“开发者错误”消息而失败的问题,而应用内结算的其他方面也有效吗?

谢谢你的时间!

2 个答案:

答案 0 :(得分:20)

我遇到了同样的问题。如果您的广告资源中有超过20个SKU,则会出现此问题。

解决方案是以块的形式获取SKU详细信息。将querySkuDetails中的IabHelper.java替换为:

int querySkuDetails(String itemType, Inventory inv, List<String> moreSkus)
    throws RemoteException, JSONException {
    logDebug("Querying SKU details.");
    ArrayList<String> skuList = new ArrayList<String>();
    skuList.addAll(inv.getAllOwnedSkus(itemType));
    if (moreSkus != null) {
        for (String sku : moreSkus) {
            if (!skuList.contains(sku)) {
                skuList.add(sku);
            }
        }
    }

    if (skuList.size() == 0) {
        logDebug("queryPrices: nothing to do because there are no SKUs.");
        return BILLING_RESPONSE_RESULT_OK;
    }

    while (skuList.size() > 0) {
        ArrayList<String> skuSubList = new ArrayList<String>(
                skuList.subList(0, Math.min(19, skuList.size())));
        skuList.removeAll(skuSubList);

        Bundle querySkus = new Bundle();
        querySkus.putStringArrayList(GET_SKU_DETAILS_ITEM_LIST, skuSubList);
        Bundle skuDetails = mService.getSkuDetails(3,
                mContext.getPackageName(), itemType, querySkus);

        if (!skuDetails.containsKey(RESPONSE_GET_SKU_DETAILS_LIST)) {
            int response = getResponseCodeFromBundle(skuDetails);
            if (response != BILLING_RESPONSE_RESULT_OK) {
                logDebug("getSkuDetails() failed: "
                        + getResponseDesc(response));
                return response;
            } else {
                logError("getSkuDetails() returned a bundle with neither an error nor a detail list.");
                return IABHELPER_BAD_RESPONSE;
            }
        }

        ArrayList<String> responseList = skuDetails
                .getStringArrayList(RESPONSE_GET_SKU_DETAILS_LIST);

        for (String thisResponse : responseList) {
            SkuDetails d = new SkuDetails(itemType, thisResponse);
            logDebug("Got sku details: " + d);
            inv.addSkuDetails(d);
        }
    }
    return BILLING_RESPONSE_RESULT_OK;
}

这种方法可以获得18个块的SKU。它对我有用。

答案 1 :(得分:3)

SKU的数量并不总是原因。谷歌改变了开发者游戏商店的工作方式后,这也开始变得越来越容易。

之前,我们只需上传签名的APK而不发布它。

现在,有Beta和Alpha部分,您必须上传已签名的APK和发布以便用户进行应用内购买。不要忘记将自己添加到测试人员列表中并正确设置测试版用户列表。