【问题标题】:How to obtain a p12 file (key.p12) from Google Cloud?如何从 Google Cloud 获取 p12 文件(key.p12)?
【发布时间】: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


【解决方案1】:

DalmoTo 在他们的评论中链接了该视频,该视频显示了如何/在何处获取密钥:youtu.be/asrCdWFrF0A?t=76

但是,Google_Auth_AssertionCredentials 似乎不应再使用 (https://github.com/googleapis/google-api-php-client/blob/master/UPGRADING.md)。相反,请使用$client->setAuthConfig('/path/to/service-account.json')。那么就可以使用json密钥文件,而不是p12密钥文件。

【讨论】:

    猜你喜欢
    • 2013-08-22
    • 2015-03-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-24
    • 2018-07-22
    • 2021-05-22
    • 2015-09-27
    相关资源
    最近更新 更多