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进行通信的另一种方式?