Question

I have followed all the instructions here: https://developers.google.com/bigquery/bigquery-api-quickstart

But have been unable to get the auhtorization process to work. Even though I am specify urn: ietf:wg:oauth:2.0:oob as my callback the URL generated tries localhost. When I run my script I get the follow output, the webpage opens but I am never prompted for my code. What am I doing wrong here? I am using the full example code from bottom of API quickstart page.

 % python bqexample.py
WARNING:root:This function, oauth2client.tools.run(), and the use of the gflags library are deprecated and will be removed in a future version of the library.
Your browser has been opened to visit:

    https://accounts.google.com/o/oauth2/auth?scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fbigquery&redirect_uri=http%3A%2F%2Flocalhost%3A8080%2F&response_type=code&client_id=(REMOVED).apps.googleusercontent.com&access_type=offline

If your browser is on a different machine then exit and re-run
this application with the command-line parameter

  --noauth_local_webserver
Était-ce utile?

La solution

It looks like the oauth2client changed to use argparse instead of gflags (i.e changed the mechanism for registering flags). Try changing the code that currently says

credentials = run(flow, STORAGE)

to

import argparse
from oauth2client import tools
argparser = argparse.ArgumentParser(
    description=__doc__,
    formatter_class=argparse.RawDescriptionHelpFormatter,
    parents=[tools.argparser])
flags = argparser.parse_args(sys.argv[1:])
credentials = tools.run_flow(flow, storage, flags)

Then, you shold be able to run

python bqexample.py --noauth_local_webserver

and it will give you a URL to cut and paste rather than trying to start up a webserver to automate the process.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top