Skip to content

Instantly share code, notes, and snippets.

@dbjpanda
dbjpanda / google-api.php
Last active February 3, 2023 09:10
Google API Ouath2 authentication using PHP and Curl
<?php
$end_point = 'https://accounts.google.com/o/oauth2/v2/auth';
$client_id = 'YOUR_ID';
$client_secret = 'YOUR_SECRET';
$redirect_uri = 'http://'.$_SERVER["HTTP_HOST"].$_SERVER["REQUEST_URI"]'; // http://'.$_SERVER["HTTP_HOST"].$_SERVER["REQUEST_URI"] or urn:ietf:wg:oauth:2.0:oob
$scope = 'https://www.googleapis.com/auth/drive.metadata.readonly';
$authUrl = $end_point.'?'.http_build_query([