---
title: "googlePlay接入小记"
author: "贝壳水母"
date: "2015-07-27T17:39:14Z"
tags: []
categories: ["移动开发"]
slug: "googleplay"
draft: false
lastmod: "2015-10-10T16:48:05Z"
id: 2230682
url: "https://shineonly.iteye.com/blog/2230682"
---

在GFW和google拐弯抹角的文档的关照下，调试googlePlay的登录和充值花了好多时间，分享一下遇到的问题和解决方法

1.充值测试手机环境
如果能登录play store，也绑定了visa/master信用卡，但是只能见到免费游戏和APP，请寻找一个境外ip的vpn……嗯，ip是重点。
直到能看到收费项目，就可以开始测试了，在这之前，如果进行iab的初始化，大概会报

```logcat
Error checking for billing v3 support
```



==============================================================


2.添加测试账号
登录play game services需要在这里的“添加测试人员”加入测试账号：
![](http://dl2.iteye.com/upload/attachment/0111/0002/2bd2e274-a815-3248-88e9-57f214d0a05c.png)
也可以直接加入一个群组：
![](http://dl2.iteye.com/upload/attachment/0111/0004/30434993-32d4-3ada-aa04-77a040799fca.png)


充值测试需要在这里的“许可测试”加：

![](http://dl2.iteye.com/upload/attachment/0111/0006/4a30767d-9a9b-316c-afeb-c98cd7b7cb00.png)



==============================================================



3.各种报错
================================

```logcat
In-app billing error: Unable to buy item, Error response: 7:Item Already Owned
```

这个问题源于iab的流程：<http://developer.android.com/google/play/billing/api.html>
一个商品支付完成后，需要被消费掉才能继续购买，所以参照例子在QueryInventoryFinishedListener和OnIabPurchaseFinishedListener适当的地方调用IabHelper的consumeAsync方法

================================

```logcat
Error consuming response: 6:Error
```

加完consumeAsync我就遇到这个报错，消费失败，隐约记得这个报错是跟测试环境有关，但是搜半天搜不到解决办法，而且也无法继续测试支付了，就放着没管，时间是周五，结果周一回来打开手机居然就成功了，嗯，隐约记得上一次也好像是这样……好吧……google好像什么地方都有缓存，改个什么都得等半天才生效

================================

```logcat
Can't start async operation (launchPurchaseFlow) because another async operation(launchPurchaseFlow) is in progress
```

这是我一次支付完成之后，想要进行第二次支付报的错，大概就是第一次的支付没有结束云云，其实就是IabHelper的状态没有改变，支付完成之后没有调flagEndAsync()这个方法，后来发现是粗心了，在例子的MainActivity上，有这么一段代码

```java
@Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        Log.d(TAG, "onActivityResult(" + requestCode + "," + resultCode + "," + data);
        if (mHelper == null) return;

        // Pass on the activity result to the helper for handling
        if (!mHelper.handleActivityResult(requestCode, resultCode, data)) {
            // not handled, so handle it ourselves (here's where you'd
            // perform any handling of activity results not related to in-app
            // billing...
            super.onActivityResult(requestCode, resultCode, data);
        }
        else {
            Log.d(TAG, "onActivityResult handled by IABUtil.");
        }
    }
```

里面的注释写得很明白了，需要在onActivityResult调一下IabHelper的handleActivityResult，里面就有一个操作

```java
// end of async purchase operation that started on launchPurchaseFlow
        flagEndAsync();
```


================================

```logcat
Unable to retrieve application xxxxxx from network
BasicNetwork.performRequest: Unexpected response code 401 for https://www.googleapis.com/games/v1/players/me?language=zh_CN
There is no linked app associated with this client ID.
```



```logcat
Application ID xxxxxxx is not associated with package xx.xx.xx. Check the application ID in your manifest.
```



这都是使用非测试人员登录googlePlay出现的报错，或者play services没有打开alpha/beta测试人员的开关，参照第2点加入测试人员即可


================================

```logcat
Access Not Configured. Please use Google Developers Console to activate the API for your project.
```


去到 <https://console.developers.google.com/project>
点开“APIs & auth”->"Credentials"->点击项目名
在
Signing-certificate fingerprint
填入keystore的SHA1的值


5. 参考文档
G+登录 <https://developers.google.com/identity/sign-in/android/>
play game services <https://developers.google.com/games/services/android/quickstart>