Search code examples
phpoauthgoogle-oauth

error while using google oauth first time


I was following the tutorial provided by google to use google oauth. I have never done it before. I followed the tutorial from top to bottom, created a new application in credentials page and etc however, I failed. I am trying this on my main server. I have given the following error :

Warning: require_once(/home/storxlbq/public_html/google/google-api-php-client/autoload.php): failed to open stream: No such file or directory in /home/storxlbq/public_html/google/index.php on line 2

Fatal error: require_once(): Failed opening required '/home/storxlbq/public_html/google/google-api-php-client/autoload.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/storxlbq/public_html/google/index.php on line 2

The tutorial link is here

and the php code I have used is here:

<?php
require_once dirname(__FILE__) . '/google-api-php-client/autoload.php';

session_start();

$client = new Google_Client();
$client->setAuthConfigFile('client_secrets.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://' . $_SERVER['HTTP_HOST'] . '/google/callback.php';
   header('Location: ' . filter_var($redirect_uri, FILTER_SANITIZE_URL));
}
?>

I have googled a bit and found every tutorial looked same except the part where some asks for google drive information, some google analytics or google+ profile. So where am I getting wrong?

Thank you.


Solution

  • Your path in require_once is wrong. In the tutorial it is require_once __DIR__.'/vendor/autoload.php';. Don't forget to run composer when you deploy it the first time.