我想从服务器端验证应用内购买
https://developers.google.com/android-publisher/api-ref/purchases/products#methods https://developers.google.com/android-publisher/api-ref/purchases/products/get
遵循服务帐户的步骤:Android : inApp purchase receipt validation google play
require('vendor / autoload.php'); 尝试{
$packageName = 'com.xxxxxxxx';
$productId = 'sample_test_xxxxxx';
$token = 'xxxxx.AO-xxxxxxxx-PqArNBB9IJW3Qt_eovcQJao3K5vmQ2QSirR77UwLieqBRYZIQvUl0NxxxxxxxC';
// create new Google Client
$client = new \Google_Client();
$client->setAuthConfig('ff110acf136.json');
$client->addScope('https://www.googleapis.com/auth/androidpublisher');
$service = new \Google_Service_AndroidPublisher($client);
$purchase = $service->purchases_products->get($packageName, $productId, $token);
}捕获(Google_Auth_Exception $ e){ //如果对Google的调用失败,则引发异常
throw new Exception('Error validating transaction', 500);
}
致命错误:未捕获的异常“ Google_Service_Exception”,带有消息“
“错误”:
“错误”:
“ domain”:“ androidpublisher”,
“ reason”:“ permissionDenied”,
“ message”:“当前用户没有足够的权限来执行请求的操作。”
“代码”:401,
“ message”:“当前用户没有足够的权限来执行请求的操作。”
D:\ xampp \ htdocs \ google-api-php-client-master \ src \ Google \ Http \ REST.php:118堆栈跟踪:#0
D:\ xampp \ htdocs \ google-api-php-client-master \ src \ Google \ Http \ REST.php(94):
Google_Http_REST :: decodeHttpResponse(Object(GuzzleHttp \ Psr7 \ Response),Object(GuzzleHttp \ Psr7 \ Request),'Google_Service _...')#1
[internal function]: Google_Http_REST::doExecute(Object(GuzzleHttp\Client), Object(GuzzleHttp\Psr7\Request), 'Google_Service_...') #2
D:\ xampp \ htdocs \ google-api-php-client-master \ src \ Google \ Task \ Runner.php(176):call_user_func_array(Array,Array)#3
D:\ xampp \ htdocs \ google-api-php-client-master \ src \ Google \ Http \ REST.php(58):Google_Task_R in
D:\ xampp \ htdocs \ google-api-php-client-master \ src \ Google \ Http \ REST.php在第118行