【问题标题】:Authentication of Cron Job to Access Big Query对 Cron 作业进行身份验证以访问 Bigquery
【发布时间】:2014-10-18 09:38:42
【问题描述】:

我正在尝试在 Google App Engine 中设置一个 cron 作业,该作业对同一域下其他项目中的 Big Query 数据具有读/写权限。 cron 作业运行一个没有用户交互或来自 Web 浏览器的任何其他输入的 Python 模块,因此 Big Query 访问的身份验证不能基于用户的登录信息。在这种情况下实现身份验证的最佳方法是什么? 我在这里尝试了解决方案:Write Cron Job in Java on GAE to Run BigQuery

但是当我点击 Big Query API 时它给了我 401 错误。

【问题讨论】:

  • 你试过这个developers.google.com/bigquery/… 吗?
  • 我已经尝试过了,我得到:“...client.py:493] 由于 401 正在刷新”
  • 你能发布你的代码吗?链接的答案对我有用。

标签: google-app-engine python-2.7 google-bigquery


【解决方案1】:

链接的代码对我来说没有问题。

import httplib2
from apiclient.discovery import build
from oauth2client.appengine import AppAssertionCredentials

scope = 'https://www.googleapis.com/auth/bigquery'
credentials = AppAssertionCredentials(scope=scope)
http = credentials.authorize(httplib2.Http())

print build("bigquery", "v2", http=http).datasets().list(projectId='gdelt-bq').execute(http)

确保在您的项目控制台上激活 BigQuery:

https://console.developers.google.com/project/YOUR_PROJECT/apiui/api

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-11-07
    • 2017-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-03
    • 2021-10-26
    • 2021-04-25
    • 1970-01-01
    相关资源
    最近更新 更多