使用服务帐号验证 Google InAppPurchase [英] Use service account to verify Google InAppPurchase

查看:42
本文介绍了使用服务帐号验证 Google InAppPurchase的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I've tried so many things in the last days but now I'm out of ideas :(

我想验证在我的 android 应用程序中制作的 inAppPurchase.

I want to verify an inAppPurchase that has been made in my android app.

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

1) I created a new service account in the google API console.

1a) 服务帐户在权限下列出并且具有可以查看"权限

1a) The service account is listed unter permissions and has "can view" permission

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

2) I'm using the most current version of https://github.com/google/google-api-php-client

3) 来自我的 PHP 脚本的代码片段:

3) code snippet from my PHP script:

$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 的回复:

4) Response from Google:

GET https://www.googleapis.com/androidpublisher/v1.1/applications/de.test.myapp/inapp/de.test.inapp.google.balance5eur/purchases/[PURCHASETOKEN]:(401) 当前用户没有足够的权限来执行请求的操作.

GET https://www.googleapis.com/androidpublisher/v1.1/applications/de.test.myapp/inapp/de.test.inapp.google.balance5eur/purchases/[PURCHASETOKEN]: (401) The current user has insufficient permissions to perform the requested operation.

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

[PURCHASETOKEN] is the purchase token I received from google

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

5) Setting $cred->sub = 'foo@bar.de' to my mail address brings up

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

Error refreshing the OAuth2 token, message: '{ "error" : "unauthorized_client", "error_description" : "Unauthorized client or scope in request." }'

推荐答案

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

Ok I found the solution!

您必须将您的 API 与您的应用程序连接起来.您必须转到您的 Google Play 发布页面 (https://play.google.com/apps/publish) 并在 Settings->User account & 中使用服务帐户电子邮件邀请用户权限->邀请新用户并授予其查看财务报告"权限.

You must to connect your API with your app. You must go to your Google Play publish page (https://play.google.com/apps/publish) and invite a user with the service account email in Settings->User account & rights->Invite new user and give it the privileges of "View financial reports".

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

This means that, whereas you normally might see a number of users from your domain listed in the Google Play Console (Email: user1@mydomain.com, Role: Finance; Email: user2@mydomain.com, Role: Administrator), you will now add another user and give him a Finance role (Email: XXX@developer.gserviceaccount.com, Role: Finance).

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

Thanks works for me, good luck!

这篇关于使用服务帐号验证 Google InAppPurchase的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆