Created
March 8, 2020 03:41
-
-
Save AdamZWinter/fb1829a5c10a71d393eb52c6d84e9b24 to your computer and use it in GitHub Desktop.
POST with PHP file_get_contents to Google API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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