2013-12-18 35 views
0

我們需要從舊供應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'), $鍵) );

回答

1

轉到https://cloud.google.com/console
選擇項目
點擊「API和驗證」
點擊「證書」
點擊「創建新客戶端ID」
選擇「服務帳戶」
點擊「創建客戶端ID'
您的私鑰將被下載。
您的公鑰將被存儲並顯示在控制檯中。
您將無法再次檢索私鑰。 Google只會發送一次。如果丟失它,則必須重新執行該過程,並更新應用程序中的相關設置。
如果已經回答了這個問題,請將其標記爲這樣。

相關問題