Hi All,
I have the same problem with retrieving of
refresh token for oauth2 with php/curl, I try to retrieve it doing step by step as described here
https://developers.google.com/android-publisher/authorization, but on point 4 I have problem
"4. Exchange this code for an access and refresh token pair by sending a POST
request to
https://accounts.google.com/o/oauth2/token
with the
following fields set:"
define ('OAUTH_TOKEN_URL', '
https://accounts.google.com/o/oauth2/token');
define ('OAUTH_GRANT_TYPE', 'authorization_code');
define ('OAUTH_CODE', 'This Code Is Hidden By Me');
define ('OAUTH_CLIENT_ID', 'This Code Is Hidden By Me');
define ('OAUTH_CLIENT_SECRET', 'This Code Is Hidden By Me');
define ('OAUTH_REDIRECT_URI', '
http://projects.snapp.info/ecr2/response.php');
//-------------------------------------------------------------------------
private function getAccessRefreshToken () {
$authTokenUrl = OAUTH_TOKEN_URL;
$parameters['grant_type'] = OAUTH_GRANT_TYPE;
$parameters['code'] = OAUTH_CODE;
$parameters['client_id'] = OAUTH_CLIENT_ID;
$parameters['client_secret'] = OAUTH_CLIENT_SECRET;
$parameters['redirect_uri'] = OAUTH_REDIRECT_URI;
return $this->doPostCURL($authTokenUrl, $parameters);
}
//-------------------------------------------------------------------------
protected function doPostCURL($url, $parameters) {
//open connection
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_VERBOSE, 0);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible;)");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $parameters);
curl_setopt($ch, CURLOPT_URL, $url);
//execute post
$result = curl_exec($ch);
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($code == 200) {
$result = json_decode($result, TRUE);
}
else {
echo "===ERROR CODE START===================\n";
echo $code;
echo "\n===ERROR CODE END===================\n\n";
}
curl_close($ch);
return $result;
}
Here is the result of execution of the code above:===ERROR CODE START===================
400
===ERROR CODE END===================
string(511) "HTTP/1.1 400 Bad Request
Content-Type: application/json; charset=utf-8
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Pragma: no-cache
Expires: Fri, 01 Jan 1990 00:00:00 GMT
Date: Mon, 12 May 2014 08:05:17 GMT
Content-Disposition: attachment; filename="json.txt"; filename*=UTF-8''json.txt
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block
Server: GSE
Alternate-Protocol: 443:quic
Transfer-Encoding: chunked
{
"error" : "invalid_grant"
}"
I have checked server clock synchronization:
zdr@inspiron:/etc# ntpdate
ntp.ubuntu.com12 May 11:11:40 ntpdate[4890]: adjust time server 91.189.89.199 offset 0.009995 sec
Is the time offset normal? Even the server clock is synchronized, the system returns me the same error.
Can you please give me an advice for resolving of this issue?
Thanks.
Best Regards
Zdravko Shishmanov