我正在使用google-api-php-client 0.6.1而且我想知道有没有办法冒充具体用户的服务帐号?我的应用程序需要在其谷歌硬盘中存储一些文件.所以,我决定使用服务帐户和.p12密钥 - 验证.它运行良好,但所有文件都存储在服务帐户中,因此我无法管理它们.我希望将文档存储在特定帐户(用于创建api项目和服务帐户本身).我试图使用这段代码:
$KEY_FILE = <p12 key file path>;
$key = file_get_contents($KEY_FILE);
$auth = new Google_AssertionCredentials(
$SERVICE_ACCOUNT_NAME,
array('https://www.googleapis.com/auth/drive'),
$key);
$auth->prn = '<certainuser@gmail.com>';
$client = new Google_Client();
$client->setUseObjects(true);
$client->setAssertionCredentials($auth);
return new Google_DriveService($client);
Run Code Online (Sandbox Code Playgroud)
但是我收到了"刷新OAuth2令牌时出错,消息:'{"error":"access_denied"}'"