douzongmu2543 2012-07-30 22:38
浏览 22
已采纳

Google Drive PHP API V2列出时没有结果

I'm creating a module for joomla that lists the the contents of a given folder. This module works as a service, so no OAuth should be required. I'm stuck since every request I make has the same answer, no items. So I would like to know if I'm creating the client/service in a wrong way or I may have registered the application in a wrong way. Here is the code:

// 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() . "
";
    // Error message is formatted as "Error calling <REQUEST METHOD> <REQUEST URL>: (<CODE>) <MESSAGE OR REASON>".
    print "Error message: " . $e->getMessage() . "
";    
} catch (apiException $e) {
    // Other error.
    print "An error occurred: (" . $e->getCode() . ") " . $e->getMessage() . "
";
} catch (Exception $e) {
    print "Cannot retrieve the files";
    print($e->getMessage());
}

Sorry to ask such a noob question but this is driving me crazy Thanks

P.S. just for the record, I followed this google-api-php-client/wiki/OAuth2#Service_Accounts

  • 写回答

1条回答 默认 最新

  • douzhuiqiu4923 2012-07-31 09:43
    关注

    After having a second look to the documentation I found that Google Drive does not support service accounts. I don't know if this is going to change but, with the requirements I have (I need to show in the web is what an end user uploads to a folder (which is public) using the desktop app) I think I cannot use google drive as a valid solution.

    I found a solution but I don't like to much since I should have to refresh the token forever Google Drive SDK Service Account Error

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 Revit2020下载问题
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 单片机无法进入HAL_TIM_PWM_PulseFinishedCallback回调函数