0
試圖從個人帳戶使用谷歌/ apiclient列出我的文件,並不能成功。我的腳步Authless訪問谷歌驅動器api
- 創建的服務帳戶
- 啓用域代表團
- 下載的按鍵(服務帳戶,而不是客戶代表)
- 使用谷歌API客戶端連接(下面的代碼)
初始化和上市
private function _initClient(string $keyLocation)
{
if (empty($keyLocation) || !file_exists($keyLocation))
{
throw new \Exception("Missing google certificate file");
}
$client = new \Google_Client();
$client->setApplicationName('My App');
$client->useApplicationDefaultCredentials();
$client->setSubject("[email protected]");
$client->setScopes([
'https://www.googleapis.com/auth/drive',
]);
return $client;
}
public function listDirectories()
{
$drive = new \Google_Service_Drive($this->client);
$files = $drive->files->listFiles([
'corpus' => 'user',
'spaces' => 'drive'
]);
var_dump($files);
}
require_once 'vendor/autoload.php';
$key = __DIR__.DIRECTORY_SEPARATOR.'client_id.json';
putenv('GOOGLE_APPLICATION_CREDENTIALS='.$key);
$t = new Myclass($key);
$t->listDirectories();
作爲迴應,我得到:
Uncaught Google_Service_Exception: { "error": "unauthorized_client", "error_description": "Client is unauthorized to retrieve access tokens using this method." }
所以,主要的問題是我缺少的是什麼?我可以在哪裏預授權我的委託帳戶?或者有沒有用戶確認與Drive Api進行通信的另一種方式?