第一次使用谷歌oauth时出错


error while using google oauth first time

我按照谷歌提供的教程使用谷歌oauth。我以前从未做过。我从上到下遵循了教程,在凭据页面等中创建了一个新的应用程序,但我失败了。我正在我的主服务器上尝试这个。我给出了以下错误:

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

教程链接在这里

我使用的php代码在这里:

<?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));
}
?>

我在谷歌上搜索了一下,发现除了一些人要求谷歌驱动器信息、一些谷歌分析或google+个人资料的部分外,每个教程看起来都一样。那么我哪里错了?

谢谢。

您在require_once中的路径错误。在本教程中,它是require_once __DIR__.'/vendor/autoload.php';。当您第一次部署composer时,不要忘记运行它。