我在最後的日子裏嘗試了很多事情,但現在我的想法:(使用服務帳戶來驗證谷歌InAppPurchase
我想驗證已經在我的Android應用已經取得了inAppPurchase。
1)我在google API控制檯中創建了一個新的服務帳戶。
1A)服務帳戶列出的Unter權限和具有「可以查看」的權限
2)我使用https://github.com/google/google-api-php-client
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 = '[email protected]per.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)響應:
GET https://www.googleapis.com/androidpublisher/v1.1/applications/de.test.myapp/inapp/de.test.inapp.google.balance5eur/purchases/[PURCHASETOKEN]: (401)當前用戶沒有足夠的權限執行請求的操作 。
[PURCHASETOKEN]我是從谷歌收到的購買令牌
5)設置$ cred->子= '[email protected]' 到我的郵箱地址帶來了
錯誤刷新OAuth2令牌,消息:'{「error」: 「unauthorized_client」,「error_description」:「未經授權的客戶端或請求中的 範圍。 }'
你救了我的一天!非常感謝你!爲什麼這不在Google文檔中記錄? – glutorange
太棒了,謝謝!你剛從頭痛中拯救了我...... – Mike
不幸的是,這並不能解決我的問題。相同的錯誤響應。 「將您的API與您的應用連接起來」是什麼意思?那是添加服務帳戶電子郵件嗎? –