【问题标题】:Google API client authorization: Internal Server Error 500Google API 客户端授权:内部服务器错误 500
【发布时间】:2017-01-22 10:12:31
【问题描述】:

我在远程 Web 服务器上使用 OAuth 2.0 for Web Server Applications 示例代码。

$client->authenticate(...) 原因

内部服务器错误 500。

不知道为什么,你能帮我吗?

这里是网址:http://imperiousgroup.com/gdrive/

这里是代码:

//index.php

require_once(__DIR__ ."/api/vendor/autoload.php");

session_start();

$client = new Google_Client();

$client->setAuthConfig('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'] . '/gdrive/oauth2callback.php';

    header('Location: ' . filter_var($redirect_uri, FILTER_SANITIZE_URL));

}


//oauth2callback.php

require_once __DIR__ .'/api/vendor/autoload.php';

session_start();

$client = new Google_Client();

$client->setAuthConfigFile('client_secrets.json');

$client->setRedirectUri('http://' . $_SERVER['HTTP_HOST'] . '/gdrive/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']);

}

【问题讨论】:

  • 请格式化代码,以提高可读性,谢谢!

标签: php api web authorization internal-server-error


【解决方案1】:

您使用的是哪个 PHP 版本? 我在使用 PHP 5.3 时遇到了类似的问题,而 google api 在技术上需要 5.4+。

如果更新它不是一个选项,我可以通过使用此处描述的解决方案来解决我的特定问题: SO link

curl_reset() 的调用位于 google api 客户端文件夹的 /vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php 中。

【讨论】:

    猜你喜欢
    • 2017-02-22
    • 2019-03-10
    • 1970-01-01
    • 2022-08-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-14
    • 1970-01-01
    相关资源
    最近更新 更多