正常的流程: 参考 https://github.com/googleapis/google-api-php-client
//安卓支付成功后传过来的
$product_id = '0001';
$purchase_token = 'xxxxxxx';
$package_name = 'com.xxxxx';
//注册好service account后下载秘钥json文件
putenv('GOOGLE_APPLICATION_CREDENTIALS=/path/to/xxxx.json');
$google_client = new \Google_Client();
$google_client->useApplicationDefaultCredentials();
$google_client->addScope(\Google_Service_AndroidPublisher::ANDROIDPUBLISHER);
$androidPublishService = new \Google_Service_AndroidPublisher($google_client);
$result = $androidPublishService->purchases_products->get(
$package_name,
$product_id,
$purchase_token
);
看上去一切都很完美,然鹅,问题来了。。。
{
"code" : 401,
"errors" : [ {
"domain" : "androidpublisher",
"message" : "The current user has insufficient permissions to perform the requested operation.",
"reason" : "permissionDenied"
} ],
"message" : "The current user has insufficient permissions to perform the requested operation."
}
死活都是401。。。没道理啊,我新建的service account是project owner啊,为什么呢。。。
原来要把新建的service account的那个email加到测试组里
然后,你懂的。。。。