回答

0

進入Developer Console並在相應的項目中,在API和身份驗證 - >憑據下,爲服務帳戶創建一個新的ClientID。爲服務帳戶創建一個ClientID應該生成一個JSON密鑰文件。你的CLIENT_KEY_PATH應該指向那個。

一個基本的服務帳戶身份驗證可能看起來像:

$client = new Google_Client(); 
$client->setClientId(clientID); 
$client->setApplicationName(applicationName); 
$client->setAssertionCredentials(new Google_Auth_AssertionCredentials(
    clientEmail, 
    array('https://spreadsheets.google.com/feeds', 'https://docs.google.com/feeds'), 
    file_get_contents(CLIENT_KEY_PATH), 
    clientKey 
)); 
$client->getAuth()->refreshTokenWithAssertion();