服务帐户(403)禁止Google Play应用内结算购买状态API [英] service account (403) Forbidden Google Play In-app Billing Purchase Status API

查看:1037
本文介绍了服务帐户(403)禁止Google Play应用内结算购买状态API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 <?php 
include_once('./ src / Google_Client.php');
include_once('./ src / contrib / Google_AndroidpublisherService.php');
$ b $ //用户令牌,格式为json
$ ANDROIDUsertoken ='{orderId:12999763169054705758.1323390433376399,packageName:org.luan.hellocpp,productId: 1\" , purchaseTime:1394183520430 purchaseState:0 purchaseToken: rurmodmieoumgowoquecqhnv.AO-J1Ow43-aM8CXNWlUcUYmA06bIaYzZPcCJCua0lLxnihOULX27Jg6NvqNUlWMpoENxtdHCIVSm6AM2mVkiC0ABSch2JEKmu1zqsVM46L762H5ppF4AIcE};
$ user_token = json_decode($ ANDROIDUsertoken,true);

// https://developers.google.com/console/help/#service_accounts
const CLIENT_ID ='1048550291137-rfqol5nm4k9tqr0a5bupedoakhd184k4.apps.googleusercontent.com';
const SERVICE_ACCOUNT_NAME ='1048550291137-rfqol5nm4k9tqr0a5bupedoakhd184k4@developer.gserviceaccount.com';
const KEY_FILE ='./key.p12';

$ client = new Google_Client();
$ client-> setApplicationName($ user_token ['packageName']);
$ client-> setClientId(CLIENT_ID);

$ key = file_get_contents(KEY_FILE);

$ auth = new Google_AssertionCredentials(
SERVICE_ACCOUNT_NAME,
数组('https://www.googleapis.com/auth/androidpublisher'),
$ key) ;

$ client-> setAssertionCredentials($ auth);

// $ client-> getAuth() - > refreshTokenWithAssertion();
// $ accessToken = $ client-> getAccessToken();
// $ client-> setAccessToken($ accessToken);

$ AndroidPublisherService =新的Google_AndroidPublisherService($ client);
$ res = $ AndroidPublisherService-> inapppurchases-> get($ user_token ['packageName'],$ user_token ['productId'],$ user_token ['purchaseToken']);

var_dump($ res);
?>

回错:

  PHP致命错误:未捕获异常'Google_ServiceException',并显示消息'Error calling GET https://www.googleapis.com/androidpublisher/v1.1/applications/org.luan.hellocpp/inapp/1/purchases /rurmodmieoumgowoquecqhnv.AO-J1Ow43-aM8CXNWlUcUYmA06bIaYzZPcCJCua0lLxnihOULX27Jg6NvqNUlWMpoENxtdHCIVSm6AM2mVkiC0ABSch2JEKmu1zqsVM46L762H5ppF4AIcE:(403)在/var/www/debug/google/src/io/Google_REST.php:66 
堆栈跟踪禁止:
#0的/ var / WWW /debug/google/src/io/Google_REST.php(36):Google_REST :: decodeHttpResponse(Object(Google_HttpRequest))
#1 /var/www/debug/google/src/service/Google_ServiceResource.php(186 ):Google_REST :: execute(Object(Google_HttpRequest))
#2 /var/www/debug/google/src/contrib/Google_AndroidpublisherService.php(39):Google_ServiceResource-> __ call('get',Array)
#3 /var/www/debug/google/purchase.php(32):Google_InapppurchasesServiceResource-> get('org.luan.helloc ...' ,'1','rurmodmieoumgow ...')
#4 {main}
在第66行输入/var/www/debug/google/src/io/Google_REST.php

当我使用服务帐户查询购物状态api时,我得到了Forbidden错误403。
Google Developers Console中Google Play Android Developer API的状态已设置。
谁可以帮助我。谢谢

解决方案

我刚解决了这个问题。



服务帐户电子邮件(1048550291137-rfqol5nm4k9tqr0a5bupedoakhd184k4@developer.gserviceaccount.com)在您的Google Play发布页面( https:// play .google.com / apps / publish / ,而不是Google开发者控制台)。



位于设置 - 用户帐户和权限,邀请新用户,使用服务帐户电子邮件提交,检查查看财务报告权利,然后凡事工作正常〜$ / b $ b

<?php
include_once('./src/Google_Client.php');
include_once('./src/contrib/Google_AndroidpublisherService.php');

//user token, in json format
$ANDROIDUsertoken = '{"orderId":"12999763169054705758.1323390433376399","packageName":"org.luan.hellocpp","productId":"1","purchaseTime":1394183520430,"purchaseState":0,"purchaseToken":"rurmodmieoumgowoquecqhnv.AO-J1Ow43-aM8CXNWlUcUYmA06bIaYzZPcCJCua0lLxnihOULX27Jg6NvqNUlWMpoENxtdHCIVSm6AM2mVkiC0ABSch2JEKmu1zqsVM46L762H5ppF4AIcE"}';
$user_token= json_decode($ANDROIDUsertoken,true);

// https://developers.google.com/console/help/#service_accounts
const CLIENT_ID = '1048550291137-rfqol5nm4k9tqr0a5bupedoakhd184k4.apps.googleusercontent.com';
const SERVICE_ACCOUNT_NAME = '1048550291137-rfqol5nm4k9tqr0a5bupedoakhd184k4@developer.gserviceaccount.com';
const KEY_FILE = './key.p12';

$client = new Google_Client();
$client->setApplicationName($user_token['packageName']);
$client->setClientId(CLIENT_ID);

$key = file_get_contents(KEY_FILE);

$auth = new Google_AssertionCredentials(
    SERVICE_ACCOUNT_NAME,
    array('https://www.googleapis.com/auth/androidpublisher'),
    $key);

$client->setAssertionCredentials($auth);

//$client->getAuth()->refreshTokenWithAssertion();
//$accessToken=$client->getAccessToken();
//$client->setAccessToken($accessToken);

$AndroidPublisherService = new Google_AndroidPublisherService($client);
$res = $AndroidPublisherService->inapppurchases->get($user_token['packageName'], $user_token['productId'], $user_token['purchaseToken']);

var_dump($res);
?>

error back :

PHP Fatal error:  Uncaught exception 'Google_ServiceException' with message 'Error calling GET https://www.googleapis.com/androidpublisher/v1.1/applications/org.luan.hellocpp/inapp/1/purchases/rurmodmieoumgowoquecqhnv.AO-J1Ow43-aM8CXNWlUcUYmA06bIaYzZPcCJCua0lLxnihOULX27Jg6NvqNUlWMpoENxtdHCIVSm6AM2mVkiC0ABSch2JEKmu1zqsVM46L762H5ppF4AIcE: (403) Forbidden' in /var/www/debug/google/src/io/Google_REST.php:66
Stack trace:
#0 /var/www/debug/google/src/io/Google_REST.php(36): Google_REST::decodeHttpResponse(Object(Google_HttpRequest))
#1 /var/www/debug/google/src/service/Google_ServiceResource.php(186): Google_REST::execute(Object(Google_HttpRequest))
#2 /var/www/debug/google/src/contrib/Google_AndroidpublisherService.php(39): Google_ServiceResource->__call('get', Array)
#3 /var/www/debug/google/purchase.php(32): Google_InapppurchasesServiceResource->get('org.luan.helloc...', '1', 'rurmodmieoumgow...')
#4 {main}
  thrown in /var/www/debug/google/src/io/Google_REST.php on line 66

I got Forbidden error 403 when i use service account to query purchase status api. The status of Google Play Android Developer API in Google Developers Console has been setted on. who can help me. thanks

解决方案

I just solved this problem.

You must add the service account email ("1048550291137-rfqol5nm4k9tqr0a5bupedoakhd184k4@developer.gserviceaccount.com") in your google play publish page(https://play.google.com/apps/publish/, not the google developer console).

at "Settings"-"User account & rights", "Invite new user", submit with service account email, check the "View financial reports" right, then everythings works ok~

这篇关于服务帐户(403)禁止Google Play应用内结算购买状态API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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