sahilg1410 / google-api-php-client

Automatically exported from code.google.com/p/google-api-php-client
Apache License 2.0
0 stars 0 forks source link

Getting error : Uncaught exception 'Google_AuthException' with message 'Error fetching OAuth2 access token, message: 'invalid_client'' #252

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Hi 
I am going to use 
http://code.google.com/p/google-api-php-client/source/browse/trunk/examples/user
info/index.php code 

I have set all the  keys related to my account 

// $client->setClientId('insert_your_oauth2_client_id');
// $client->setClientSecret('insert_your_oauth2_client_secret');
// $client->setRedirectUri('insert_your_redirect_uri');
// $client->setDeveloperKey('insert_your_developer_key');

Once i authorize the application after login into my google account i am 
getting the error 

Fatal error: Uncaught exception 'Google_AuthException' with message 'Error 
fetching OAuth2 access token, message: 'invalid_client'' in 
/home/content/60/8051460/html/DFA-Reporting-PHP-examples/src/auth/Google_OAuth2.
php:113 Stack trace: #0 
/home/content/60/8051460/html/DFA-Reporting-PHP-examples/src/Google_Client.php(1
31): Google_OAuth2->authenticate(Array, '4/Sasr3YdriSuJN...') #1 
/home/content/60/8051460/html/DFA-Reporting-PHP-examples/examples/userinfo/index
.php(32): Google_Client->authenticate('4/Sasr3YdriSuJN...') #2 {main} thrown in 
/home/content/60/8051460/html/DFA-Reporting-PHP-examples/src/auth/Google_OAuth2.
php on line 113

You can check it from 
http://fuzonmedia.com/DFA-Reporting-PHP-examples/examples/userinfo/index.php 

Note : once authorized it is redirected to my server page with some code value 
into the url .

Do you have any idea what is wrong ? or how can i fix that problem 

Thanks

Original issue reported on code.google.com by niladrid...@gmail.com on 22 Jan 2013 at 9:21

GoogleCodeExporter commented 9 years ago
That error is due to the client ID not matching the one the code was requested 
for. Make sure you have configured you client ID before calling authenticate.

Original comment by ianbar...@google.com on 22 Mar 2013 at 4:49

GoogleCodeExporter commented 9 years ago
i ma having the same problem..plz tell me how to get rid off this problem

Original comment by parveen...@gmail.com on 27 Oct 2014 at 7:38

GoogleCodeExporter commented 9 years ago
I got the same problem too.

Fatal error: Uncaught exception 'Google_AuthException' with message 'Error 
fetching OAuth2 access token, message: ''' in 
/home/rodabagu/public_html/google/google2/src/auth/Google_OAuth2.php:113 Stack 
trace: #0 /home/rodabagu/public_html/google/google2/src/Google_Client.php(131): 
Google_OAuth2->authenticate(Array, '4/nn_lPl2CNFakY...') #1 
/home/rodabagu/public_html/google/google2/index.php(46): 
Google_Client->authenticate('4/nn_lPl2CNFakY...') #2 {main} thrown in 
/home/rodabagu/public_html/google/google2/src/auth/Google_OAuth2.php on line 113

Original comment by binoto8...@gmail.com on 26 Nov 2014 at 4:45

GoogleCodeExporter commented 9 years ago
i got too the same..... pls help me............

Original comment by 3.45am2...@gmail.com on 27 Nov 2014 at 8:38

GoogleCodeExporter commented 9 years ago
had same issue . fixed it by deleting the extra space from the client secret. 
when u copy it from google api console you get an extra space. 

Original comment by luck...@gmail.com on 15 Dec 2014 at 12:14

GoogleCodeExporter commented 9 years ago
hwo to sort this error!....none of the above solutions help

Original comment by abhinavb...@gmail.com on 6 Jan 2015 at 8:19

GoogleCodeExporter commented 9 years ago
copying client id again resolved it for me. Such a waste of time..

Original comment by govind.c...@gmail.com on 8 Jan 2015 at 6:41

GoogleCodeExporter commented 9 years ago
here is the working code

require_once 'src/Google/Client.php';
error_reporting(-1);
session_start();

$client = new Google_Client();
$client->setApplicationName('P');
$client->setClientId('373253997411-0i5gu266sdg06ie1dn8vq05r774laa2246.apps.googl
eusercontent.com');
$client->setClientSecret('1234hjghghhghgx55ai');
$client->setRedirectUri('http://myserver.net/google/authenticate.php');
$client->setScopes('https://www.googleapis.com/auth/content');
$merchantId = '1993090';

if (isset($_SESSION['oauth_access_token'])) {
    $client->setAccessType('offline');
    $client->setAccessToken($_SESSION['oauth_access_token']);
} elseif (isset($_GET['code'])) {
    $client->setAccessType('offline');
    $token = $client->authenticate($_GET['code']);
    $_SESSION['oauth_access_token'] = $token;

} else
    header('Location: ' . $client->createAuthUrl());

require_once 'src/Google/Service/ShoppingContent.php';

Original comment by govind.c...@gmail.com on 8 Jan 2015 at 6:44

GoogleCodeExporter commented 9 years ago
As per the openid connect spec the workflow should go like this and i was 
getting the same error for a while, if anything is different at any one point 
you will receive the aforementioned error.

Client clicks the button and then they are redirected to authorization page 
(client to server)

Client is then redirected back with a code (client to server)

This code is exchanged with the openid server (server to server)

The server responds with an openid credentials (server to server)

The code that is being exchanged at point 3 will check to see whether you are 
using the same credentials to authorize the application as you started with, 
this is the main area where you will receive errors if any.

step 1 will be where the first check takes place so it could also error there :)

This is the very simplistic explanation but it gives you an idea where to start 
diagnosing the problem. 

The issue i had is that i was sending a redirect to the wrong end of my 
application (having a testing and a production side) thus the credentials were 
wrong and the client wasn't authorized to access the application even if the 
credentials were correct :P. 

Thanks again, 

Steve p.

Original comment by clientre...@reflex.london on 3 Mar 2015 at 3:07