Hi,
I’m working in Google OAuth2 and I am stuck in this part:
«You can try out that call using the curl command line application, substituting the code you got from the above example URL—note that you may need to urlencode your redirect and secret, as curl won’t automatically do that for you:
POST /o/oauth2/token HTTP/1.1
Host: accounts.google.com
Content-Type: application/x-www-form-urlencoded
code=4/P7q7W91a-oMsCeLvIaQm6bTrgtp6&
client_id=21302922996.apps.googleusercontent.com&
client_secret=XTHhXh1SlUNgvyWGwDk1EjXB&
redirect_uri=https://www.example.com/back&
grant_type=authorization_code
curl https://accounts.google.com/o/oauth2/token -d
“code=4/P7q7W91a-oMsCeLvIaQm6bTrgtp6&client_id=21302922996.apps.googleusercontent.com&client_secret=XTHhXh1SlUNgvyWGwDk1EjXB&redirect_uri=https://www.example.com/back&grant_type=authorization_code”
»
What am I doing wrong?
Not receiving a postive reply from the curl
$url = 'https://accounts.google.com/o/oauth2/token?'.urlencode('code=4/P7q7W91a-oMsCeLvIaQm6bTrgtp6&client_id=21302922996.apps.googleusercontent.com&client_secret=XTHhXh1SlUNgvyWGwDk1EjXB&redirect_uri=https://www.example.com/back&grant_type=authorization_code');
var_dump(get_web_page($url));
function get_web_page( $url )
{
$options = array(
CURLOPT_RETURNTRANSFER => true, // return web page
CURLOPT_HEADER => false, // don't return headers
CURLOPT_FOLLOWLOCATION => true, // follow redirects
CURLOPT_AUTOREFERER => true, // set referer on redirect
CURLOPT_CONNECTTIMEOUT => 120, // timeout on connect
CURLOPT_TIMEOUT => 120, // timeout on response
CURLOPT_MAXREDIRS => 10, // stop after 10 redirects
);
$ch = curl_init( $url );
curl_setopt_array( $ch, $options );
$content = curl_exec( $ch );
$err = curl_errno( $ch );
$errmsg = curl_error( $ch );
$header = curl_getinfo( $ch );
curl_close( $ch );
$header['errno'] = $err;
$header['errmsg'] = $errmsg;
$header['content'] = $content;
return $header;
}