如何使用Google OAuth授权已安装的应用程序访问BiqQuery?

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
1个回答

3
看起来oauth2client已经改为使用argparse而不是gflags注册flag。尝试更改当前代码中的以下部分:
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)

然后,你应该可以运行。
python bqexample.py --noauth_local_webserver

它会给您一个URL来复制并粘贴,而不是试图启动Web服务器自动完成该过程。


2
谢谢!这个有效了,看起来他们的教程需要更新一下。 - calumb
1
是的...文档错误已经被报告了。我也在oauth2client问题跟踪器中表示,新的操作方式更为复杂。 - Jordan Tigani

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接