Create A Index.php and paste below code.
require_once __DIR__ . '/vendor/autoload.php';
function getClient()
{
$client = new Google_Client();
$client->setAuthConfig( __DIR__ .'/client_secret.json');
$client->setScopes(['https://spreadsheets.google.com/feeds','https://www.googleapis.com/auth/drive','https://docs.google.com/feeds/']);
$client->setAccessType('offline');
$authUrl = $client->createAuthUrl();
header("location:".$authUrl);
}
Then Create another callback.php for redirect page and paste below code. #Please Make sure that you have entered this redirect url in client_secret.json And Google Developer Api Project too. And You Ready To go.
require_once __DIR__ . '/vendor/autoload.php';
$client = new Google_Client();
$client->setAuthConfig( __DIR__ .'/client_secret.json');
$client->setScopes(['https://www.googleapis.com/auth/spreadsheets','https://www.googleapis.com/auth/drive']);
$client->authenticate($_GET['code']);
$access_token = $client->getAccessToken();