【问题标题】:Use service account to verify Google InAppPurchase使用服务帐号验证 Google InAppPurchase
【发布时间】:2016-04-15 12:32:33
【问题描述】:

最近几天我尝试了很多东西,但现在我没有想法:(

我想验证在我的 android 应用中创建的 inAppPurchase。

1) 我在 google API 控制台中创建了一个新的服务帐户。

1a) 服务帐户列在权限下,并具有“可以查看”权限

2) 我使用的是最新版本的https://github.com/google/google-api-php-client

3) 我的 PHP 脚本中的代码 sn-p:

$client = new Google_Client(); 
$client->setApplicationName('myAppName' );
$client->setClientId('123456789123-vxoasdt8qwe6awerc9ysdfmjysdfysf64werweria8fh.apps.googleusercontent.com');
$key = file_get_contents('/shr/data/stor/b516cexx3123asdf3988345d8133e7f86bfas2553-privatekey.p12');
$service_account_name = '123456789123-vxoasdt8qwe6awerc9ysdfmjysdfysf64werweria8fh@developer.gserviceaccount.com';

$client->setScopes(array('https://www.googleapis.com/auth/androidpublisher') );
$cred = new Google_Auth_AssertionCredentials( $service_account_name, array('https://www.googleapis.com/auth/androidpublisher'), $key );
$client->setAssertionCredentials($cred);

try {  
    $service = new Google_Service_AndroidPublisher( $client ); 
    $googleApiResult = $service->inapppurchases->get($externalAppId, $externalProductId, $purchaseToken);
} catch (Exception $e) {  
    var_dump( $e->getMessage() ); 
}

4) 谷歌的回应:

获取https://www.googleapis.com/androidpublisher/v1.1/applications/de.test.myapp/inapp/de.test.inapp.google.balance5eur/purchases/[PURCHASETOKEN]: (401) 当前用户权限不足,无法执行 请求的操作。

[PURCHASETOKEN] 是我从 google 收到的购买令牌

5) 将 $cred->sub = 'foo@bar.de' 设置为我的邮件地址会弹出

刷新 OAuth2 令牌时出错,消息:'{ "error" : "unauthorized_client", "error_description" : "未经授权的客户端或 请求范围。” }'

【问题讨论】:

    标签: php android api google-api-php-client publisher


    【解决方案1】:

    好的,我找到了解决方案!

    您必须将您的 API 与您的应用程序连接起来。您必须进入您的 Google Play 发布页面 (https://play.google.com/apps/publish) 并在设置->用户帐户和权限->邀请新用户并授予其“查看财务报告”权限中使用服务帐户电子邮件邀请用户。

    这意味着,虽然您通常会在 Google Play 管理中心中看到来自您域的一些用户(电子邮件:user1@mydomain.com,角色:财务;电子邮件:user2@mydomain.com,角色:管理员) ,您现在将添加另一个用户并给他一个财务角色(电子邮件:XXX@developer.gserviceaccount.com,角色:财务)。

    感谢为我工作,祝你好运!

    【讨论】:

    • 你拯救了我的一天!非常感谢!为什么 Google 文档中没有记录这一点?
    • 不幸的是,这并不能解决我的问题。相同的错误响应。 “将您的 API 与您的应用程序连接起来”是什么意思?这是添加服务帐户电子邮件吗?
    • 这里有一些关于在 google play 帐户之间转移应用程序的文档,这就是导致我收到 401 错误的原因。 support.google.com/googleplay/android-developer/checklist/…
    • @BobMitchell “将您的 API 与您的应用程序连接”是指“授权您的应用程序获取您拥有和接收的 google play 发布帐户的‘财务’信息(如应用程序购买和应用内购买)通过 Google Api 进行购买”。因此,您必须在您的 google play 发布者页面中为您用作 clientid 的用户(“123456789123-vxoasdt8qwe6awerc9ysdfmjysdfysf64werweria8fh.apps.googleusercontent.com”)授予访问财务信息的权限。希望对你有帮助。
    • 我正在尝试进行应用购买验证,请求是 GET googleapis.com/androidpublisher/v2/applications/[packageName]/…。此外,据我所知,我已经配置了所有内容,将 API 与应用程序链接,向我创建的用户授予管理员权限,获得令牌等,但它一直抛出 401 错误“当前用户有权限不足,无法执行请求的操作。”有任何想法吗?我怎样才能提供比管理员允许的更多的权限?。
    猜你喜欢
    • 2013-07-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-02
    • 1970-01-01
    • 2019-01-23
    • 1970-01-01
    • 2017-03-01
    相关资源
    最近更新 更多