php – 使用服务帐户验证Google InAppPurchase

我在过去几天尝试了这么多事情,但现在我没有想法:(

我想验证在我的Android应用程序中已经做了一个inAppPurchase.

1)我在Google Api控制台中创建了一个新的服务帐户.

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

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

3)我的PHP脚本的代码段:

$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)Google的回应:

GET 07001:
(401) The current user has insufficient permissions to perform the
requested operation.

[PURCHASetoKEN] is the purchase token I received from google

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

Error refreshing the OAuth2 token,message: ‘{ “error” :
“unauthorized_client”,“error_description” : “Unauthorized client or
scope in request.” }’

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

您必须连接您的API与您的应用程序.您必须访问Google Play发布页面(https://play.google.com/apps/publish),并在“设置” – >“用户帐户”中邀请具有服务帐户电子邮件用户.权限 – >邀请新用户并授予其“查看财务报告”的权限.

这意味着,您通常可能会在Google Play控制台(电子邮件:user1@mydomain.com,角色:财务;电子邮件:user2@mydomain.com,角色:管理员)中看到您的域中的许多用户,您将现在添加一个用户并给他一个财务角色(电子邮件:XXX@developer.gserviceaccount.com,角色:财务).

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

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...