Google OAuth 2 authorization - swapping code for token

I'm trying to implement Google OAuth 2 to get access to Google APIs. I follow this guide, using server-side scenario.

I have no problem with getting the code, server redirects to localhost (which is the only server allowed in redirect URIs for now). To achieve this, I go to https://accounts.google.com/o/oauth2/auth?client_id=whatever.apps.googleusercontent.com&redirect_uri=http://localhost/&scope=https://www.google.com/m8/feeds/&response_type=code page.

Then, I tried using curl (as in guide) to test, if Google's server responds with access token. However, it seems to fail very hard. Only response I can get is {"error":"invalid_client"}. I'm sure I provide everything Google wants me to provide - code, client ID, client secret, redirect URI (localhost) and grant_type=authorization_code.

Whole curl command line is:

curl https://accounts.google.com/o/oauth2/token -d "code=&client_id=whatever.apps.googleusercontent.com&client_secret=&redirect_uri=http://localhost&grant_type=authorization_code"

Am I missing something? How can I exchange code for access token?

7
задан Kara 29 December 2013 в 08:52
поделиться