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.