Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/280.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用服务帐户验证Google InAppPurchase_Php_Android_Api_Google Api Php Client_Publisher - Fatal编程技术网

Php 使用服务帐户验证Google InAppPurchase

Php 使用服务帐户验证Google InAppPurchase,php,android,api,google-api-php-client,publisher,Php,Android,Api,Google Api Php Client,Publisher,在过去的几天里,我尝试了很多东西,但现在我已经没有主意了:( 我想验证在我的android应用程序中进行的InApp购买 1) 我在GoogleAPI控制台中创建了一个新的服务帐户 1a)服务帐户按权限列出,并具有“可查看”权限 2) 我使用的是最新版本的 3) 我的PHP脚本中的代码片段: $client = new Google_Client(); $client->setApplicationName('myAppName' ); $client->setClientId('

在过去的几天里,我尝试了很多东西,但现在我已经没有主意了:(

我想验证在我的android应用程序中进行的InApp购买

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

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

2) 我使用的是最新版本的

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) 谷歌的回应:

获取: (401)当前用户没有足够的权限执行 请求的操作

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

5) 设置$cred->sub=foo@bar.de“给我的邮箱地址带来了

刷新OAuth2令牌时出错,消息:'{“错误”: “未经授权的客户端”,“错误描述”:“未经授权的客户端或 请求中的作用域。“}”


好的,我找到了解决办法

您必须将API与应用程序连接起来。您必须转到您的Google Play发布页面()并在设置->用户帐户和权限->邀请新用户中邀请具有服务帐户电子邮件的用户,并授予其“查看财务报告”的权限

这意味着,虽然您通常会在Google Play控制台(电子邮件:user1@mydomain.com,职位:财务;电子邮件:user2@mydomain.com,角色:管理员),您现在将添加另一个用户并给他一个财务角色(电子邮件:XXX@developer.gserviceaccount.com,角色:财务)


谢谢为我工作,祝你好运

你救了我一天!非常感谢你!为什么谷歌文档中没有记录这一点?不幸的是,这并不能解决我的问题。相同的错误响应。“将API与应用程序连接”是什么意思?这是在添加服务帐户电子邮件吗?以下是一些关于在google play帐户之间传输应用程序的文档,这是导致我出现401错误的原因@BobMitchell“将你的API与你的应用程序连接”是指“授权你的应用程序通过谷歌API获取你拥有并接收购买的谷歌play发布帐户的“财务”信息(如应用程序购买和应用程序内购买)。因此,您必须为您在google play publisher页面中用作clientid的用户授予访问财务信息的权限(“123456789123-VxOASDT8QWE6AWERC9YSDFMJYSDFF64WERWERIA8FH.apps.googleusercontent.com”)。我希望它能帮助你。我正在尝试进行应用内购买验证,请求是get。此外,据我所知,我已经配置了所有内容,将API与应用程序链接,向我创建的用户授予管理员权限,获取令牌,等等,但它不断抛出401错误“当前用户没有足够的权限执行请求的操作”。有什么想法吗?我如何授予超出管理员允许的权限?。