Reputation: 59
I'm trying to get Access_token which I need to use in adsense host api to authorization my request and I have code like this
$curlHandle = curl_init();
$data = array(
'code' => 'AFC',
'client_id' => 'myClientId',
'client_secret'=> 'myClientSecret',
'redirect_uri' => 'http://smk.dev',
'grant_type'=>'authorization_code'
);
$url = 'https://accounts.google.com/o/oauth2/token';
curl_setopt($curlHandle,CURLOPT_URL,$url);
curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curlHandle, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($curlHandle, CURLOPT_POST, 1);
curl_setopt($curlHandle, CURLOPT_POSTFIELDS, $data);
curl_setopt($curlHandle, CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec($curlHandle);
$data = json_decode($result);
But i get response with error "invalid_grant" so where i am wrong? what is the code parameter? i use parameter from google adsense host api
Upvotes: 0
Views: 875
Reputation: 109
It's a multi-step process
Take a look at this (Mainly the first picture) https://developers.google.com/identity/protocols/OAuth2
Upvotes: 0