3

我已按照此处的所有说明进行操作:https ://developers.google.com/bigquery/bigquery-api-quickstart

但一直无法使授权过程正常工作。即使我指定 urn: ietf:wg:oauth:2.0:oob 作为回调,生成的 URL 也会尝试 localhost。当我运行我的脚本时,我得到以下输出,网页打开,但从未提示我输入我的代码。我在这里做错了什么?我正在使用 API 快速入门页面底部的完整示例代码。

 % 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
4

1 回答 1

3

看起来 oauth2client 更改为使用 argparse 而不是 gflags(即更改了注册标志的机制)。尝试更改当前显示的代码

credentials = run(flow, STORAGE)

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)

然后,你应该能够运行

python bqexample.py --noauth_local_webserver

它会给你一个 URL 来剪切和粘贴,而不是尝试启动一个网络服务器来自动化这个过程。

于 2014-03-30T18:41:57.253 回答