0

Does anyone try to get a google play or whatever google api by oauth2client.client? Some, I wrote the next bits of code:

import httplib2
import requests
from oauth2client.client import flow_from_clientsecrets

flow = flow_from_clientsecrets('path_to_dir\\client_secret.json',
                               scope = 'https://www.googleapis.com/auth/androidpublisher',
                               redirect_uri='')
auth_uri = flow.step1_get_authorize_url()
credentials = flow.step2_exchange(code)
http = httplib2.Http()
http = credentials.authorize(http)

I wonder how to get code parametr? The error is:

NameError: name 'code' is not defined

and how to call any method of the choosed api?

Leo
  • 649
  • 3
  • 9
  • 20

1 Answers1

0

The Google OAuth2 library redirects the user to the Google login page (for the first time). When the user confirms your web application can use his personal information, Google server makes an HTTP request to your "redirect_uri" address with the "code" parameter that you need.

You have to listen on the URL defined in "redirect_uri" param. Then get the "code" parameter from the HTTP request.

See for details: https://developers.google.com/api-client-library/python/guide/aaa_oauth

Example application for Django framework: https://code.google.com/p/google-api-python-client/source/browse/#hg%2Fsamples%2Fdjango_sample

  • yeah, I've read that article, and a managed to look the code from the browser. Hovewer, I could use the code value in script, got an error `invalid_grantCode was already redeemed` – Leo Apr 09 '15 at 13:39