【发布时间】:2021-09-29 22:16:29
【问题描述】:
我需要从https://console.cloud.google.com/ 下载我的 key.p12 文件,但我现在不知道该怎么做。 我的仪表板“Api & Services > Credentials”是这样的:
我需要此 p12 文件以使用此代码连接到 PHP API Google_Service_AndroidPublisher(我在此 Stackoverflow 对问题 Get android subscription status, failed with 403 的回答中使用相同的代码:
$service_account_name = 'testing@nootrictesting.iam.gserviceaccount.com'; //Your service account email
$key_file_location = ''; // p12 file (key.p12)
$client = new Google_Client();
$client->setApplicationName("My name app"); //This is the name of the linked application
$key = file_get_contents($key_file_location);
$cred = new Google_Auth_AssertionCredentials(
$service_account_name,
array('https://www.googleapis.com/auth/androidpublisher'),
$key
);
$client->setAssertionCredentials($cred);
if($client->getAuth()->isAccessTokenExpired()) {
$client->getAuth()->refreshTokenWithAssertion($cred);
}
$apiKey = ""; //API key
$client->setDeveloperKey($apiKey);
$service = new Google_Service_AndroidPublisher($client);
$results = $service->purchases_subscriptions->get("MY_ANDROID_APP_PACKAGE", $product_id, $purchase_token, array());
任何帮助都会很有用。 谢谢!!!
【问题讨论】:
-
youtu.be/asrCdWFrF0A?t=76 如果你能找到使用它的代码,你真的应该考虑使用 json 密钥文件而不是 p12。
标签: android google-api subscription in-app