谷歌云端硬盘 PHP API V2 列出时没有结果


Google Drive PHP API V2 No results when listing

我正在为joomla创建一个模块,列出给定文件夹的内容。此模块作为服务工作,因此不需要 OAuth。我被困住了,因为我提出的每个请求都有相同的答案,没有项目。所以我想知道我是否以错误的方式创建客户端/服务,或者我可能以错误的方式注册了应用程序。这是代码:

// this class is where I have all the IDs from the google console
require_once(dirname(__FILE__) . '/gdrive/config.php');
require_once(dirname(__FILE__) . '/gdrive/gd-v2-php/apiClient.php');
require_once(dirname(__FILE__) . '/gdrive/gd-v2-php/contrib/apiDriveService.php');
$client = new apiClient();
$key    = file_get_contents(Config::KEY_FILE);
$client->setClientId(Config::CLIENT_ID);
$client->setUseObjects(true);
$client->setAssertionCredentials(new apiAssertionCredentials(
    Config::SERVICE_ACCOUNT_NAME,
    array('https://www.googleapis.com/auth/drive'), $key)
);
$service = new apiDriveService($client);
try {
    $parameters = array();
    $parameters['maxResults'] = $maxResults;
    $files = $service->files->listFiles($parameters);
    $items = $files->getItems();
    var_dump($items);
    $pageToken = $files->getNextPageToken();
} catch (apiServiceException $e) {
    print "Error code :" . $e->getCode() . "'n";
    // Error message is formatted as "Error calling <REQUEST METHOD> <REQUEST URL>: (<CODE>) <MESSAGE OR REASON>".
    print "Error message: " . $e->getMessage() . "'n";    
} catch (apiException $e) {
    // Other error.
    print "An error occurred: (" . $e->getCode() . ") " . $e->getMessage() . "'n";
} catch (Exception $e) {
    print "Cannot retrieve the files";
    print($e->getMessage());
}

很抱歉问这样一个菜鸟问题,但这让我发疯谢谢

P.S. 只是为了记录,我遵循了这个 google-api-php-client/wiki/OAuth2#Service_Accounts

再次查看文档后,我发现Google云端硬盘不支持服务帐户。我不知道这是否会改变,但是,根据我的要求(我需要在网络上显示最终用户使用桌面应用程序上传到文件夹(公共(的内容(,我认为我不能使用 google 云端硬盘作为有效的解决方案。

我找到了一个解决方案,但我不太喜欢,因为我应该永远刷新令牌 谷歌云端硬盘SDK服务帐户错误