android - 如何从 Google Cloud 获取 p12 文件(key.p12)?
问题描述
我需要从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());
任何帮助都会很有用。谢谢!!!
解决方案
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 密钥文件。
推荐阅读
- asp.net-core - 复杂类型数组的OpenApi 3多部分表单请求
- css - 如何在 Material UI 中插入变量类名?
- amazon-web-services - AWS Glue 架构注册表导入
- git - P4merge 作为 Git 合并工具
- c++ - 在哨兵中使用 C++ 函数名称映射崩溃或不响应地址
- python - 如何根据每个元素中的某些信息对列表的元素进行分组?
- docker - 无法从 docker 运行 tensorflow 服务
- docker - 两个 docker 网络之间的 Http 请求
- python - 从两个单独的数组中的文件读取数据
- c# - 如何从任务列表中启动异步任务?或如何计算任务?