$code, "client_id" => $client_id, "client_secret" => $client_secret, "redirect_uri" => $demo_redirect_uri, "grant_type" => "authorization_code" ); $curl = curl_init($oauth2token_url); curl_setopt($curl, CURLOPT_POST, true); curl_setopt($curl, CURLOPT_POSTFIELDS, $clienttoken_post); curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); $json_response = curl_exec($curl); curl_close($curl); $authObj = json_decode($json_response); if (isset($authObj->refresh_token)){ global $refreshToken; $refreshToken = $authObj->refresh_token; } $accessToken = $authObj->access_token; return $accessToken; } //calls api and gets the data function call_api($accessToken,$url){ $curl = curl_init($url); curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); $curlheader[0] = "Authorization: Bearer " . $accessToken; curl_setopt($curl, CURLOPT_HTTPHEADER, $curlheader); $json_response = curl_exec($curl); curl_close($curl); $responseObj = json_decode($json_response); return $responseObj; } $loginUrl = sprintf("https://accounts.google.com/o/oauth2/auth?scope=%s&state=%s&redirect_uri=%s&response_type=code&client_id=%s",$demo_scope,$state,$demo_redirect_uri,$client_id); ?>
Grant access with Google account for basic user info
Demo will return the name on your Google account. It does not ask for offline access.
You can revoke access by:
The name on your Google account is: " . $your_name . "
"; session_unset(); } if(isset($_REQUEST['error'])){ echo "Error: " . $_REQUEST['error'] . "
"; } ?>