【问题标题】:error while using google oauth first time第一次使用google oauth时出错
【发布时间】:2016-07-15 02:55:37
【问题描述】:

我正在按照 google 提供的教程使用 google 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

教程链接是here

我使用的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));
}
?>

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

谢谢。

【问题讨论】:

    标签: php oauth google-oauth


    【解决方案1】:

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

    【讨论】:

    • 谢谢哥们。我从 php/laravel 继续前进。但是,我会接受它猜测它的正确答案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-07-20
    • 2021-02-23
    • 2013-12-26
    • 2015-08-13
    • 2015-07-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多