0

Fatal error: Uncaught exception 'Google_AuthException' with message 'Error fetching OAuth2 access token, message: 'invalid_grant'' in /var/www/html/edplace/dev2568/cron_files/google-api-php-client/src/auth/Google_OAuth2.php:115 Stack trace: #0 /var/www/html/edplace/dev2568/cron_files/google-api-php-client/src/Google_Client.php(131): Google_OAuth2->authenticate(Array, '4/He7CoB42K1zSX...') #1 /var/www/html/edplace/dev2568/cron_files/cron_job_for_export_and_sent_parent_list_to_google_drive.php(126): Google_Client->authenticate('4/He7CoB42K1zSX...') #2 /var/www/html/edplace/dev2568/cron_files/cron_job_for_export_and_sent_parent_list_to_google_drive.php(7): export_to_csv(Array) #3 {main} thrown in /var/www/html/edplace/dev2568/cron_files/google-api-php-client/src/auth/Google_OAuth2.php on line 115

error_reporting(E_ALL);
ini_set('display_errors', 1);

$clientId = "xxx"; 
$clientSecret = "xxx"; 
$authCode = "4/xxxx"; 

require_once("google-api-php-client/src/Google_Client.php");
require_once("google-api-php-client/src/contrib/Google_DriveService.php");

$client = new Google_Client();
// Get your credentials from the APIs Console
$client->setClientId($clientId);
$client->setClientSecret($clientSecret);
$client->setRedirectUri("http://www.edplace.com/dev2568/cron_files/cron_job_for_export_and_sent_parent_list_to_google_drive.php");
$client->setScopes(array("https://www.googleapis.com/auth/drive"));
$service = new Google_DriveService($client);  
// Exchange authorisation code for access token
if(!file_exists("token.json")) 
{
    // Save token for future use
    $accessToken = $client->authenticate($authCode);      
    file_put_contents("token.json",$accessToken);  
}
else 
$accessToken = file_get_contents("token.json");

$client->setAccessToken($accessToken);

$file = new Google_DriveFile();
$file->setTitle('Parent_'.date('d_M_Y'));
$file->setDescription("Server backup file");
$file->setMimeType("text/csv");
$data = file_get_contents('a.csv');
$createdFile = $service->files->insert($file, array('data' => $data, 'mimeType' => "application/vnd.google-apps.spreadsheet",));
2
Contributors
1
Reply
16
Views
2 Years
Discussion Span
Last Post by justinbiber
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.