Anthony Jesmok
Anthony Jesmok

Reputation: 459

Uncaught exception 'Google_AuthException' with message 'Could not json decode the token'

I have been trying to use the Google Mirror API to program a sample application for Google Glass. I downloaded the PHP Quick Start for the Google Mirror API and deployed it to an Apache webserver managed by cPanel. I configured the API keys and such per the guide posted on the Glass Developers website. When I go to the URL on my machine to authenticate the application, I am successfully redirected to Google's Oauth2 service to authorize my Google account. However, when I am returned to the website to continue, I get this error:

Fatal error: Uncaught exception 'Google_AuthException' with message 'Could not json decode the token' in /home/fluffy/public_html/glass/google-api-php-client/src/auth/Google_OAuth2.php:162 Stack trace: #0 /home/fluffy/public_html/glass/google-api-php-client/src/Google_Client.php(170): Google_OAuth2->setAccessToken(NULL) #1 /home/fluffy/public_html/glass/util.php(77): Google_Client->setAccessToken(NULL) #2 /home/fluffy/public_html/glass/oauth2callback.php(45): bootstrap_new_user() #3 {main} thrown in /home/fluffy/public_html/glass/google-api-php-client/src/auth/Google_OAuth2.php on line 162

So I went into the script and had the JSON it was trying to parse echoed out to the page. The JSON array it outputs is:

{ "access_token" : "ya29.1.AADtN_VWpFG9CblS1rWSrxcj1a1arQlIv4Iuu7mQ6UWMp9kRRLpr3tsuxRIDePA3ufvi-Q", "token_type" : "Bearer", "expires_in" : 3600, "id_token" : "eyJhbGciOiJSUzI1NiIsImtpZCI6IjQ3NzZmZWE1ZWRkMzU0OTJlYmNiYWY0N2QzZTQwNWQ5NTEwYzBmYmUifQ.eyJpc3MiOiJhY2NvdW50cy5nb29nbGUuY29tIiwidG9rZW5faGFzaCI6IjRCczhpSGNiSk5qUHlYYm41SndSVFEiLCJhdF9oYXNoIjoiNEJzOGlIY2JKTmpQeVhibjVKd1JUUSIsImNpZCI6IjU1OTc1MjgyNjgzOC5hcHBzLmdvb2dsZXVzZXJjb250ZW50LmNvbSIsImF6cCI6IjU1OTc1MjgyNjgzOC5hcHBzLmdvb2dsZXVzZXJjb250ZW50LmNvbSIsImF1ZCI6IjU1OTc1MjgyNjgzOC5hcHBzLmdvb2dsZXVzZXJjb250ZW50LmNvbSIsImlkIjoiMTAyMjUxNzA3OTUyNTQ3MjY3NjEwIiwic3ViIjoiMTAyMjUxNzA3OTUyNTQ3MjY3NjEwIiwiaWF0IjoxMzg3MTYxODk5LCJleHAiOjEzODcxNjU3OTl9.AXsIeC3f0e66ko5o2hxUXrE6LxYnSDXp0CwaSHBQKsd2M4d3g6A-JWeNIVYRTeoXucaFvDlr_XpLEtWeELZ1M8ExI85aWMwI6_xI969te4xX6pLtym2e84PzZGYwMZVmX_imAl4CFB9l5nYrZO7vSelGeXsON474QUvkTbMLTEM", "refresh_token" : "REDACTED" }

So, I don't really get it. Why is the JSON coming in just fine, but it can't be parsed by the script? I've seen this posted other places online for other Google APIs, but there's no clear answer.

Upvotes: 2

Views: 4185

Answers (2)

vinod
vinod

Reputation: 2880

If all your credentials are correct, please restart your browser and check again.

Upvotes: 0

John C
John C

Reputation: 8415

Going from your stacktrace, the problem appears to arise in /home/fluffy/public_html/glass/util.php where Google_Client->setAccessToken() (line 77) is called with NULL instead of the expected JSON response.

Try checking around there (or oauth2callback.php) to make sure you are passing in the response correctly.

Upvotes: 2

Related Questions