Android APPでユーザーが以前に行った各Android購入をサーバーで確認する必要があります。google-api-php-clientを使用すると、サーバーでのトークンの認証と管理が簡単になると思います。しかし、サンプルはなく、昨日、Google はアプリ内購入サービスを提供する新しいバージョン 0.6.3 を公開しました。
フォローしました-> *code.google.com/p/google-api-php-client/wiki/OAuth2#Service_Accounts*
私のcode.google.com/apis/console/で、 「Google Play Android Developer API」をプッシュし、API Access で「サービス アカウント」を構成しました。
Android クライアント APP から、サーバーは PACKAGE_NAME、PRODUCT_ID、および購入 TOKEN を受け取ります。
私のサーバーコードは次のとおりです。
require_once '../../src/Google_Client.php';
require_once '../../src/contrib/Google_AndroidpublisherService.php';
// Set your client id, service account name, and the path to your private key.
// For more information about obtaining these keys, visit:
// https://developers.google.com/console/help/#service_accounts
const CLIENT_ID = 'asdf.apps.googleusercontent.com';
const SERVICE_ACCOUNT_NAME = 'asdf@developer.gserviceaccount.com';
// Make sure you keep your key.p12 file in a secure location, and isn't
// readable by others.
const KEY_FILE = '../../asdf/privatekey.p12';;
$client = new Google_Client();
$client->setApplicationName({APP_PACKAGE_NAME});
// Set your cached access token. Remember to replace $_SESSION with a
// real database or memcached.
session_start();
if (isset($_SESSION['token'])) {
$client->setAccessToken($_SESSION['token']);
}
// Load the key in PKCS 12 format (you need to download this from the
// Google API Console when the service account was created.
$key = file_get_contents(KEY_FILE);
$client->setAssertionCredentials(new Google_AssertionCredentials(
SERVICE_ACCOUNT_NAME,
array('https://www.googleapis.com/auth/androidpublisher'),
$key)
);
$client->setClientId(CLIENT_ID);
$service = new Google_AndroidPublisherService($client);
$res = $service->inapppurchases->get({APP_PACKAGE_NAME},{APP_PACKAGE_NAME.PRODUCT_ID}, {PURCHASE_TOKEN});
var_dump($res);
表示されたエラーは次のとおりです。
Google_ServiceException: Error calling GET https://www.googleapis.com/androidpublisher
/v1.1/applications/{APP_PACKAGE_NAME}/inapp/{APP_PACKAGE_NAME.PRODUCT_ID}/purchases
/{PURCHASE_TOKEN}: (401) This developer account does not own the application. in
/.../google-api-php-client/src/io/Google_REST.php on line 66 Call Stack: 0.0201
266376 1. {main}() ............
トークンは正しく、Google API コンソール ( https://code.google.com/apis/console ) と Google 開発者コンソール ( https://play.google.com/apps/publish ) で同じアカウントを使用しています。 / )。私はサービス アカウント API のみを使用しており、Web アプリケーションのクライアント ID と単純な API アクセスは使用していません。セキュリティのために、ここでいくつかのコード値を変更しました。
Google API を使用した購入サーバーの検証で何が問題なのかを教えてもらえますか?アプリの所有者を知るにはどうすればよいですか? Google Apis の新しいプロジェクト、プロジェクト ドメイン、プロジェクト番号、プロジェクト ID などと関係がありますか?