0

I'm using an OAuth 2.0 for Web Server Applications example code on remote web server.

$client->authenticate(...) causes 

Internal Server Error 500.

No idea why, can you help me please?

Here is the web address: http://imperiousgroup.com/gdrive/

And here is the code:

//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']);    
}
1
  • Please format the code, for better readability, thanks! Commented Jan 22, 2017 at 10:32

1 Answer 1

0

Which PHP version are you using? I had a similar issue as I was using PHP 5.3 while the google api technically requires 5.4+.

If updating it is not an option, I was able to fix my specific issue by using the solution described here: SO link

The call to curl_reset() is found in /vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php in the google api client folder.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.