【发布时间】:2014-01-07 07:22:58
【问题描述】:
我们需要从旧的配置 API 迁移到新的 Admin SDK。问题是我们无法弄清楚如何让 OAuth2 与服务帐户一起使用。我们使用以下代码作为示例,但无法确定 key.p12 文件的创建位置/方式。我在开发人员控制台中创建了一个使用 cliendId、电子邮件地址和 API 密钥与我的服务器相关联的服务帐户,并在其上安装了应用程序。如果有人可以帮助我了解如何创建 key.p12 文件,那么我很确定我可以做到这一点。
谢谢,
滑雪
// 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 = 'insert_your_client_id';
const SERVICE_ACCOUNT_NAME = 'insert_your_service_account_name';
// Make sure you keep your key.p12 file in a secure location, and isn't
// readable by others.
const KEY_FILE = '/super/secret/path/to/key.p12';
// Load the key in PKCS 12 format (you need to download this from the
// Google API Console when the service account was created.
$client = new Google_Client();
... $key = file_get_contents(KEY_FILE); $client->setClientId(CLIENT_ID); $client->setAssertionCredentials(新的 Google_AssertionCredentials( SERVICE_ACCOUNT_NAME, 数组('https://www.googleapis.com/auth/prediction'), $密钥) );
【问题讨论】:
标签: google-api oauth-2.0