Google BigQuery 的 Google App Engine 授权 [英] Google App Engine authorization for Google BigQuery
问题描述
我已按照说明进行操作https://developers.google.com/bigquery/authorization#service-accounts-appengine从应用引擎向 bigquery 进行一些查询.
I have followed the instructions in https://developers.google.com/bigquery/authorization#service-accounts-appengine to make some queries from app engine to bigquery.
在第 2 步中,我单击 Google Api 控制台中的团队,它会重定向到 App Engine > 管理 > 权限.我将服务帐户名称添加为电子邮件,并将角色添加为开发人员(可以编辑"选项不可用),然后单击邀请用户".之后,出现一条消息:一封电子邮件已发送至 xxxxxx@appspot.gserviceaccount.com 进行验证."并且状态为待定.我如何确认电子邮件?,这里似乎有一个错误...
In the step 2, I click on Team in Google Api Console and it redirects to App Engine > Administration > Permissions. I add the service account name as Email and as a role I select developer (the option "can edit" is not available), and then click "Invite user". After that, appears a message: "An email was sent to xxxxxx@appspot.gserviceaccount.com for verification." and the status is Pending. How I could confirm the email?, seems there is a bug here...
接下来,我使用以下代码进行了测试:
Next, I made a test using the following code:
#!/usr/bin/env python
import httplib2
import webapp2
from google.appengine.api import memcache
from apiclient.discovery import build
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from oauth2client.appengine import AppAssertionCredentials
# BigQuery API Settings
PROJECT_NUMBER = 'XXXXXXXX'
credentials = AppAssertionCredentials(scope='https://www.googleapis.com/auth/bigquery')
http = credentials.authorize(httplib2.Http(memcache))
service = build("bigquery", "v2", http=http)
class MainHandler(webapp2.RequestHandler):
def get(self):
query = {'query':'SELECT word,count(word) AS count FROM publicdata:samples.shakespeare GROUP BY word;',
'timeoutMs':10000}
jobRunner = service.jobs()
reply = jobRunner.query(projectId=PROJECT_NUMBER,body=query).execute()
self.response.out.write(reply)
app = webapp2.WSGIApplication([
('/', MainHandler)
], debug=True)
回复是(从谷歌运行):
And the reply was (running from google):
HttpError: <HttpError 403 when requesting https://www.googleapis.com/bigquery/v2/projects/XXXXXXXX/queries?alt=json returned "Access Denied: Job YYYYYYYY:job_e57bdde0144c495dbc864ccbfb82b704: RUN_QUERY_JOB">
如果我从本地主机测试,答案是:
If I test from localhost, the answer is:
HttpError: <HttpError 401 when requesting https://www.googleapis.com/bigquery/v2/projects/XXXXXXXX/queries?alt=json returned "Invalid Credentials">
有人可以帮助我吗?:-)
Someone could help me? :-)
推荐答案
您可以将 xxxxxx@appspot.gserviceaccount.com 添加到 http://cloud.google.com/console.
You can add the xxxxxx@appspot.gserviceaccount.com to the project at http://cloud.google.com/console.
期待这很快变得更简单/更直接!
Expect this to be easier/ more straightforward soon!
一步一步,@Christian:
Step by step, by @Christian:
- 转到应用程序的 App Engine Dashboard,点击应用程序设置并复制服务帐户名称 (xxxxxx@appspot.gserviceaccount.com)
- 转到http://cloud.google.com/console
- 选择您的项目
- 点击齿轮图标并选择团队
- 点击添加成员
- 粘贴服务帐户名称并选择可以编辑权限,然后单击添加.
- 玩得开心!
这篇关于Google BigQuery 的 Google App Engine 授权的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!