Skip to content

Instantly share code, notes, and snippets.

@AdamZWinter
Created March 8, 2020 03:41
Show Gist options
  • Save AdamZWinter/fb1829a5c10a71d393eb52c6d84e9b24 to your computer and use it in GitHub Desktop.
Save AdamZWinter/fb1829a5c10a71d393eb52c6d84e9b24 to your computer and use it in GitHub Desktop.
POST with PHP file_get_contents to Google API
$grant_type = 'refresh_token';
$url = 'https://oauth2.googleapis.com/token';
$data = array('refresh_token' => $refresh_token, 'client_id' => $client_id, 'client_secret' => $client_secret, 'redirect_uri' => $redirect_uri, 'grant_type' => $grant_type, 'scope' => $scope );
// use key 'http' even if you send the request to https://...
$options = array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => http_build_query($data)
)
);
$context = stream_context_create($options);
$strjson = file_get_contents($url, false, $context);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment