2

これがbigqueryへの認証呼び出しを試みているときに私が得ているエラーデータです

HttpError: <HttpError 400 when requesting https://www.googleapis.com/bigquery/v2/projects/ClientId/datasets/samples/tables/natality?alt=json returned "Invalid project ID 'ClientId'. Project IDs must contain 6-63 lowercase letters, digits, or dashes. IDs must start with a letter and may not end with a dash.">

これが私のmain.pyです

import httplib2
import os
from google.appengine.api import memcache
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from oauth2client.appengine import oauth2decorator_from_clientsecrets
from bqclient import BigQueryClient


PROJECT_ID = "########"  this is the Client Id 
DATASET = "samples"
TABLE = "natality"


CLIENT_SECRETS = os.path.join(os.path.dirname(__file__),
    'client_secrets.json')

http = httplib2.Http(memcache)
decorator = oauth2decorator_from_clientsecrets(CLIENT_SECRETS,
    'https://www.googleapis.com/auth/bigquery')

bq = BigQueryClient(http, decorator)

class MainHandler(webapp.RequestHandler):
    @decorator.oauth_required
    def get(self):
        self.response.out.write("Hello Dashboard!\n")
        modTime = bq.getLastModTime(PROJECT_ID, DATASET, TABLE)
        if modTime is not None:
            msg = 'Last mod time = ' + modTime
        else:
            msg = "Could not find last modification time.\n"
        self.response.out.write(msg)

application = webapp.WSGIApplication([
   ('/', MainHandler),
   (decorator.callback_path, decorator.callback_handler())
], debug=True)

def main():
   run_wsgi_app(application)

if __name__ == '__main__':
    main()

そしてここにapp.yamlがあります

application: hellomydashboard
version: 1
runtime: python
api_version: 1

handlers:
- url: /favicon\.ico
  static_files: favicon.ico
  upload: favicon\.ico

- url: .*
  script: main.py

そしてここにbqclient.pyがあります

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

class BigQueryClient(object):
    def __init__(self, http, decorator):
        """Creates the BigQuery client connection"""
        self.service = build('bigquery', 'v2', http=http)
        self.decorator = decorator

    def getTableData(self, project, dataset, table):
        decorated = self.decorator.http()
        return self.service.tables().get(projectId=project, datasetId=dataset,
            tableId=table).execute(decorated)

    def getLastModTime(self, project, dataset, table):
        data = self.getTableData(project, dataset, table)
        if data is not None and 'lastModifiedTime' in data:
            return data['lastModifiedTime']
        else:
            return None

    def Query(self, query, project, timeout_ms=10000):
        query_config = {
            'query': query,
            'timeoutMs': timeout_ms
        }
        decorated = self.decorator.http()
        result_json = (self.service.jobs()
                       .query(projectId=project, body=query_config)
                       .execute(decorated))

        return result_json

エラーで述べたように、ClientIdをプロジェクトIDに置き換えようとしましたが、別のエラーが発生します

HttpError: <HttpError 404 when requesting https://www.googleapis.com/bigquery/v2/projects/hellodashboard87/datasets/samples/tables/natality?alt=json returned "Not Found: Dataset hellodashboard87:samples">

このページのチュートリアルに従っています https://developers.google.com/bigquery/articles/dashboard#firstcall


BigQueryを使用するには、 APIコンソールでBigQueryが有効になっているプロジェクトを作成する必要があります(これを行ったと想定しています)。プロジェクトを作成すると、URLからプロジェクト番号を取得できるようになります。

https://code.google.com/apis/console/#project:12345XXXXXXX

この例では、プロジェクト番号は12345XXXXXXXであり、これはに使用する値ですPROJECT_ID

4

2 に答える 2

2

GoogleのBigQueryが提供する公開データセットを使用するには、次のパラメータを使用します。

プロジェクトIDpublicdata

データセットIDsamples

テーブルID :(natalityまたは使用したいもの)

所有しているデータセットを使用するには、プロジェクトIDをAPIコンソールダッシュボードにあるものに切り替えます。

于 2012-11-07T14:09:00.943 に答える
0

BigQuery を使用するには、BigQuery が有効になっているAPI コンソールでプロジェクトを作成する必要があります (既に作成済みであると仮定しています)。プロジェクトを作成したら、URL からプロジェクト番号を取得できます。

https://code.google.com/apis/console/#project:12345XXXXXXX

この例では、プロジェクト番号は12345XXXXXXXで、これは に使用する値ですPROJECT_ID

于 2012-11-06T17:55:57.297 に答える