doupeng2253 2013-11-19 14:38
浏览 53
已采纳

Google Drive API

I am trying to integrate Google Drive in my webpage by using the GoogleDrive API. I have copied most of the code from google.And when executing it, I have an issue with the function given. This is my code:

    $apiConfig['use_objects'] = true;
session_start();
$url_array = explode('?', 'http://'.$_SERVER ['HTTP_HOST'].$_SERVER['REQUEST_URI']);
$url = $url_array[0];
require_once 'google-api-php-client/src/Google_Client.php';
require_once 'google-api-php-client/src/contrib/Google_DriveService.php';
require_once 'google-api-php-client/src/service/Google_Service.php';
require_once 'google-api-php-client/src/service/Google_ServiceResource.php';


$client = new Google_Client();
$client->setClientId('347297625177-l6476q96da6fi65iqp0ra84e3luic5kp.apps.googleusercontent.com');
$client->setClientSecret('8UE-faGCj9xBKe8IsgP0pN2r');
$client->setRedirectUri("http://arodrisa.url.ph/GoogleDrive_example/list.php");
$client->setScopes(array('https://www.googleapis.com/auth/drive'));

echo "5";
if (isset($_GET['code'])) {
    $_SESSION['accessToken'] = $client->authenticate($_GET['code']);
    header('location:'.$url);exit;
} elseif (!isset($_SESSION['accessToken'])) {
    $client->authenticate();
}
echo"2";
$result = array();
$pageToken = NULL;



do {
  try {
    $parameters = array();
    if ($pageToken) {
      $parameters['pageToken'] = $pageToken;
    }
    $files = $service->files->listFiles($parameters);
    $list=$files['items'];
    $result = array_merge($result,$list);
    $pageToken = $files['nextPageToken'];
  } catch (Exception $e) {
    echo "An error occurred: " . $e->getMessage();
    $pageToken = NULL;
  }
} while ($pageToken);
    var_dump($result);
    include 'list.html';

I get this error:

52 Fatal error: Call to a member function listFiles() on a non-object in /home/u317564784/public_html/GoogleDrive_example/list.php on line 39

Which referes to this line:

 $files = $service->files->listFiles($parameters);

Please help me.

  • 写回答

1条回答 默认 最新

  • duankeng2026 2017-07-20 09:26
    关注

    SOLVED I have added these lines

       $client->setAccessToken($_SESSION['accessToken']); 
       $service = new Google_DriveService($client); 
       $finfo = finfo_open(FILEINFO_MIME_TYPE); 
       $file = new Google_DriveFile();
    

    before

       $files = $service->files->listFiles($parameters);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料