51
loading...
This website collects cookies to deliver better user experience
if (!isset($_SESSION['oauth']))
{
$url = 'https://accounts.google.com/o/oauth2/v2/auth?' .
'scope=https%3A//www.googleapis.com/auth/drive.file&' .
'access_type=offline&' .
'include_granted_scopes=true&' .
'response_type=code&' .
'state=state_parameter_passthrough_value&' .
'redirect_uri=https%3A//localhost:3000/redirect-login.php&' .
'client_id=' . $client_id;
header('Location: ' . $url);
exit;
}
$url = 'https://oauth2.googleapis.com/token';
$postdata = http_build_query(
array(
'code' => $code,
'client_id' => $client_id,
'client_secret' => $client_secret,
'redirect_uri' => 'https://localhost:3000/redirect-login.php',
'grant_type' => 'authorization_code'
)
);
$opts = array('http' =>
array(
'method' => 'POST',
'header' => 'Content-Type: application/x-www-form-urlencoded',
'content' => $postdata
)
);
$context = stream_context_create($opts);
$result = file_get_contents($url, false, $context);
$oauth = json_decode($_SESSION['oauth']);
$token = $oauth->access_token;
$url = 'https://www.googleapis.com/drive/v3/files';
$options = array('http' => array(
'method' => 'GET',
'header' => 'Authorization: Bearer '.$token
));
$context = stream_context_create($options);
$response = file_get_contents($url, false, $context);