第一次使用 google oauth 时出错
error while using google oauth first time
我正在按照 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
教程link是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));
}
?>
我已经 googled 了一点,发现每个教程看起来都一样,除了一些要求 google 驱动器信息、一些 google 分析或 google+ 配置文件的部分.
那么我哪里错了?
谢谢。
您在 require_once
中的路径是错误的。在教程中是 require_once __DIR__.'/vendor/autoload.php';
。第一次部署时不要忘记 运行 composer。
我正在按照 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
教程link是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));
}
?>
我已经 googled 了一点,发现每个教程看起来都一样,除了一些要求 google 驱动器信息、一些 google 分析或 google+ 配置文件的部分. 那么我哪里错了?
谢谢。
您在 require_once
中的路径是错误的。在教程中是 require_once __DIR__.'/vendor/autoload.php';
。第一次部署时不要忘记 运行 composer。