PHP code example of digitalzenworks / google-api-authorization

1. Go to this page and download the library: Download digitalzenworks/google-api-authorization library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

digitalzenworks / google-api-authorization example snippets




use DigitalZenWorks\GoogleApiAuthorization\GoogleAuthorization;
use DigitalZenWorks\GoogleApiAuthorization\Mode;

$client = Authorizer::authorize(
	Mode::Discover,
	$credentialsFilePath,
	$serviceAccountFilePath,
	$tokensFilePath,
	'Google Drive API File Uploader',
	['https://www.googleapis.com/auth/drive'],
	'http://localhost:8000/test.php',
	['promptUser' => false, 'showWarnings' => false]);

if ($client === null)
{
	echo 'Oops, authorization failed';
}
else
{
	echo 'Client is initialized and authorized, lets go';
}

		$client = Authorizer::authorizeServiceAccount(
			$serviceAccountFilePath,
			'Google Drive API File Uploader',
			['https://www.googleapis.com/auth/drive'],
			false);

		$client = Authorizer::authorizeToken(
			$credentialsFilePath,
			$tokensFilePath,
			'Google Drive API File Uploader',
			['https://www.googleapis.com/auth/drive'],
			false);

		$authorizer = new Authorizer('Google Drive API File Uploader',
		['https://www.googleapis.com/auth/drive'],
		['promptUser' => false, 'showWarnings' => false]);

		$client = $authorizer->apiAuthorize(
			Mode::Discover,
			$this->credentialsFilePath,
			$this->serviceAccountFilePath,
			$this->tokensFilePath,
			'http://localhost:8000/test.php');