我們需要從舊供應API遷移到新的Admin SDK。問題是我們無法弄清楚如何讓OAuth2使用服務帳戶。我們使用以下代碼作爲示例,但無法確定key.p12文件的創建位置/方式。我有一個cliendId,電子郵件地址和API密鑰創建的服務帳戶綁定到我的服務器與開發人員控制檯上的應用程序。如果有人可以幫助我理解如何創建key.p12文件,那麼我很確定我可以使這個工作。如何獲取OAuth2使用服務帳戶
感謝,
滑雪
// 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();
... $鍵=的file_get_contents(KEY_FILE); $ client-> setClientId(CLIENT_ID); $客戶端 - > setAssertionCredentials(新Google_AssertionCredentials( SERVICE_ACCOUNT_NAME, 陣列( 'https://www.googleapis.com/auth/prediction'), $鍵) );