Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call to undefined method Google_Service_Drive_FileList::getItems()

I am implementing the google drive API.

I have referred this google documentation https://developers.google.com/api-client-library/php/auth/web-app#example.

Here is my index.php

<?php
require_once __DIR__ . '/vendor/autoload.php';

session_start();

$client = new Google_Client();
$client->setAuthConfigFile('client_secret.json');
$client->addScope(Google_Service_Drive::DRIVE_METADATA_READONLY);

if (isset($_SESSION['access_token']) && $_SESSION['access_token']) {
    $client->setAccessToken($_SESSION['access_token']);
    $drive_service = new Google_Service_Drive($client);
    $files_list = $drive_service->files->listFiles(array())->getItems();
    echo json_encode($files_list);
} else {
    $redirect_uri = 'http://127.0.0.1/googleApiQuickstart/oauth2callback.php';
    header('Location: ' . filter_var($redirect_uri, FILTER_SANITIZE_URL));
}

And my oauth2callback.php

<?php
require_once __DIR__ . '/vendor/autoload.php';

session_start();

$client = new Google_Client();
$client->setAuthConfigFile('client_secret.json');
$client->setRedirectUri('http://127.0.0.1/googleApiQuickstart/oauth2callback.php');
$client->addScope(Google_Service_Drive::DRIVE_METADATA_READONLY);

if (!isset($_GET['code'])) {
    $auth_url = $client->createAuthUrl();
    header('Location: ' . filter_var($auth_url, FILTER_SANITIZE_URL));
} else {
    $client->authenticate($_GET['code']);
    $_SESSION['access_token'] = $client->getAccessToken();
    $redirect_uri = 'http://127.0.0.1/googleApiQuickstart';
    header('Location: ' . filter_var($redirect_uri, FILTER_SANITIZE_URL));
}

But getting the error.

Call to undefined method Google_Service_Drive_FileList::getItems()

Where am I wrong?

like image 467
Keyur Avatar asked Jun 22 '16 18:06

Keyur


1 Answers

$files_list = $drive_service->files->listFiles(array())->getItems();

change to ->

$files_list = $drive_service->files->listFiles(array())->getFiles();

seems getItems(); doesn't work any more you have to use getFiles(); instead of getItems();

like image 177
user2808421 Avatar answered Oct 10 '22 09:10

user2808421