Php Google API客户端授权:内部服务器错误500

Php Google API客户端授权:内部服务器错误500,php,api,web,authorization,internal-server-error,Php,Api,Web,Authorization,Internal Server Error,我正在使用OAuth2.0作为远程Web服务器上的Web服务器应用程序示例代码 $client->authenticate(…)原因 内部服务器错误500 不知道为什么,你能帮我吗 以下是网址: 代码如下: //index.php require_once(__DIR__ ."/api/vendor/autoload.php"); session_start(); $client = new Google_Client(); $client->setAuthConfig('clie

我正在使用OAuth2.0作为远程Web服务器上的Web服务器应用程序示例代码

$client->authenticate(…)原因

内部服务器错误500

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

以下是网址:

代码如下:

//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版本? 我在使用PHP5.3时遇到了类似的问题,而谷歌api在技术上需要5.4+

如果无法进行更新,我可以使用下面介绍的解决方案解决我的特定问题:


调用
curl\u reset()
可在google api客户端文件夹中的
/vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php中找到。

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