简体   繁体   English

如何从 Google Cloud 获取 p12 文件 (key.p12)?

[英]How to obtain a p12 file (key.p12) from Google Cloud?

I need to download my key.p12 file from https://console.cloud.google.com/ but I dont know how to do it now.我需要从https://console.cloud.google.com/下载我的 key.p12 文件,但我现在不知道该怎么做。 My Dashboard "Api & Services > Credentials" is like this:我的仪表板“Api & Services > Credentials”是这样的:

控制台云 Google 仪表板

I need this p12 file to connect to the PHP API Google_Service_AndroidPublisher with this code (I am using the same code in this Stackoverflow answer to the question Get android subscription status, failed with 403 :我需要这个 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());

Any help will be useful.任何帮助都会有用。 Thanks!!!谢谢!!!

DalmoTo linked the video in their comment that shows how/where to grab keys: youtu.be/asrCdWFrF0A?t=76 DalmoTo 在他们的评论中链接了视频,显示了如何/在哪里获取钥匙:youtu.be/asrCdWFrF0A?t=76

However, Google_Auth_AssertionCredentials looks like it shouldn't be used any longer ( https://github.com/googleapis/google-api-php-client/blob/master/UPGRADING.md ).但是, Google_Auth_AssertionCredentials 看起来不应再使用( https://github.com/googleapis/google-api-php-client/blob/master/UPGRADING.md )。 Instead, use $client->setAuthConfig('/path/to/service-account.json') .相反,使用$client->setAuthConfig('/path/to/service-account.json') Then you can use the json key file, not the p12 key file.然后你可以使用json密钥文件,而不是p12密钥文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM