I'm trying to get an access token, using the latest version of the google-api-php-client (take a look at this https://github.com/google/google-api-php-client), and I'm following this official doc: https://developers.google.com/api-client-library/php/guide/aaa_oauth2_web
The only difference is that I'd like to use the service Google_Service_Plus, instead of Google_Service_Urlshortener.
Basically I do these steps:
- I initialize the Google Client
$clientspecifying client ID, client secret, developer key, scopes and redirect URI (which points to my localhost Ubuntu 12.04 - PHP 5.3.10). - I initialize the Google Plus Service
$plususing the Google Client$client. - I redirect the user to the Auth URL using
$client->createAuthUrl(). - The user can see the Consent Page and accepts.
- I obtain an authorization code
$_GET['code']to use for token exchange. - Then, in the callback page, I try to do
$client->authenticate($_GET['code']);but google server returns HTTP 400 and I get aGoogle_Auth_Exception: Error fetching OAuth2 access token, message: 'invalid_request'.
The flow breaks here.
What's wrong?
Any help will be appreciated.
Thanks in advance,
Niccolò.