我下面這個教程獲得打破鏈接錯誤whle使用App Engine服務帳戶
https://developers.google.com/bigquery/docs/authorization#service-accounts-appengine
這裏是我的main.py代碼
import httplib2
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
SCOPE = 'https://www.googleapis.com/auth/bigquery'
PROJECT_NUMBER = 'XXXXXXXXXX' # REPLACE WITH YOUR Project ID
# Create a new API service for interacting with BigQuery
credentials = AppAssertionCredentials(scope=SCOPE)
http = credentials.authorize(httplib2.Http())
bigquery_service = build('bigquery', 'v2', http=http)
class ListDatasets(webapp.RequestHandler):
def get(self):
datasets = bigquery_service.datasets()
listReply = datasets.list(projectId=PROJECT_NUMBER).execute()
self.response.out.write('Dataset list:')
self.response.out.write(listReply)
application = webapp.WSGIApplication(
[('/listdatasets(.*)', ListDatasets)],
debug=True)
def main():
run_wsgi_app(application)
if __name__ == "__main__":
main()
這裏是我的app.yaml文件中的代碼
application: bigquerymashup
version: 1
runtime: python
api_version: 1
handlers:
- url: /favicon\.ico
static_files: favicon.ico
upload: favicon\.ico
- url: .*
script: main.py
是的,我已經添加應用程序引擎服務帳戶名稱在谷歌API控制檯團隊選項卡可以編輯權限。 當上傳應用程序,並嘗試訪問該鏈接,它說
Oops! This link appears to be broken.
Ealier我跑了本地本和嘗試使用鏈接localhost:8080
。於是我想到的可能是在本地運行,所以我上傳可能在向錯誤訪問它我代碼到
http://bigquerymashup.appspot.com/
但仍然給它錯誤。
編輯: 更新的app.yaml
application: bigquerymashup
version: 1
runtime: python
api_version: 1
handlers:
- url: /favicon\.ico
static_files: favicon.ico
upload: favicon\.ico
- url: .*
script: main.py
- url: /listdatasets
script: main.py
但是,讓另一個錯誤
Traceback (most recent call last): File "/base/python_runtime/python_lib/versions/1/google/appengine/ext/webapp/_webapp25.py", line 710, in call handler.get(*groups) TypeError: get() takes exactly 1 argument (2 given)
1.您是否在此行上添加了項目編號? PROJECT_NUMBER ='XXXXXXXXXX'#用您的項目ID替換# 2.您嘗試連接的鏈接是什麼?你的app.yaml文件是什麼樣的? –
是我添加了項目號。我已經更新了app.yaml和其他細節的問題。我嘗試使用localhost:8080和http://bigquerymashup.appspot.com/在那裏我上傳代碼 – iJade