I've been following the guide at https://developers.google.com/+/web/signin/server-side-flow to the point where I have an authorization code sent to my server. Then in PHP I attempt to get the access tokens using the following:
$data = "code=".urlencode(trim($access_code)).
"&grant_type=authorization_code".
"&client_id=".urlencode($this->client_id).
"&client_secret=".urlencode($this->client_secret).
"&redirect_uri=".urlencode(trim($redirect_uri));
$curl = curl_init("https://accounts.google.com/o/oauth2/token");
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$result = json_decode(curl_exec($curl), true);
curl_close($curl);
return $result;
The redirect_uri is EXACTLY the same in PHP as it is in the redirect uris in the google dev console, but the call always returns:
array(1) { ["error"]=> string(21) "redirect_uri_mismatch" }
What am I doing wrong?
For reference, this is what my google API setting looks like:
http://such-nom.com
http://www.such-nom.com
And the var passed as $redirect_uri:
$redir = 'http://such-nom.com';
Edit: It seems the exact same PHP works when the request token is generated serverside rather than through the google button.