我正在为 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());
}
很抱歉问了这样一个菜鸟问题,但这让我发疯了谢谢
PS只是为了记录,我遵循了这个google-api-php-client/wiki/OAuth2#Service_Accounts