<?php

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
require 'vendor/autoload.php';

define('GOOGLE_CLIENT_ID', '978753925510-5mtnh5c5322264b86g5vekpt85vshje4.apps.googleusercontent.com');
define('GOOGLE_CLIENT_SECRET', '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');
define('GOOGLE_REDIRECT_URI', 'https://lightpink-weasel-254307.hostingersite.com/oauth2callback.php'); // or your live URL


session_start();

// $client = new Google_Client();
// $client->setClientId(GOOGLE_CLIENT_ID);
// $client->setClientSecret(GOOGLE_CLIENT_SECRET);
// $client->setRedirectUri(GOOGLE_REDIRECT_URI);
// $client->addScope('https://www.googleapis.com/auth/gmail.send');



$client = new Google_Client();
$client->setClientId(GOOGLE_CLIENT_ID);
$client->setClientSecret(GOOGLE_CLIENT_SECRET);
$client->setRedirectUri('https://lightpink-weasel-254307.hostingersite.com/oauth2callback.php');
$client->setAccessType('offline');
$client->setApprovalPrompt('force');
$client->addScope("https://mail.google.com/");

if (!isset($_GET['code'])) {
    $auth_url = $client->createAuthUrl();
    header('Location: ' . filter_var($auth_url, FILTER_SANITIZE_URL));
} else {
    $client->authenticate($_GET['code']);
    $accessToken = $client->getAccessToken();
    echo "<h3>Refresh Token:</h3><pre>" . $accessToken['refresh_token'] . "</pre>";
}
