2

私は Google-bigquery と JavaScript を少しの間使用してきましたが、ここでいくつかの助けを得た後、プロジェクトに関連付けられた Google ログインの詳細を承認して、あなたがやろうとしていることを達成する必要があることに気付きました。

私が達成しようとしていること:- ユーザーが自分のページにアクセスしてデータを表示できるようにします。たとえば、天気予報に基づいて公開データを表示する場合があるため、ユーザー認証は必要ありません。

現在、研究開発目的で使用しています。Web サーバー アプリケーションに OAuth 2.0 を使用しています。プロジェクトの client-id email-id などを除いて、ユーザー データは必要ないため、これを取り除きたいと考えています。 .

OAuth 2.0 for Server to Server Applications について読んだことがありますが、JavaScript のサポートはないようですので、エンドユーザーが関与する必要はありません。

これに対する解決策または安全なクイックフィックスはありますか。このサンプルから構成コードを変更して、何が起こるかを確認しようとしましたが、うまくいきませんでした -

var config = {
            'client_id' : 'xxxxxxxxxxx.apps.googleusercontent.com',
            "iss" : "xxxxxxxxxxxxxxxxxxxxxxxxxx@developer.gserviceaccount.com",
            "scope" : "https://www.googleapis.com/auth/bigquery",
            "aud" : "https://accounts.google.com/o/oauth2/token",
            "exp" : 1328554385,
            "iat" : 1328550785
        };

ここで何が欠けていますか。

事前に助けとアドバイスをありがとう、私はこれに非常に長い間苦労してきました。

4

1 に答える 1

3

クライアント サイドの JavaScript コードにクライアント シークレットを隠す方法がないため、クライアント サイドの JavaScript アプリケーションがサーバー間の OAuth フローを介して BigQuery を使用することを承認する方法はありません。

この場合の唯一の解決策は、JavaScript アプリケーションからの API 呼び出しにサーバー側プロキシを使用することです。以下に、AppEngine を介してクエリ呼び出しをプロキシする方法のスニペットを示します (注: 以下のコードはすべてのユーザーに公開されており、呼び出しが特定の JavaScript クライアントを介して実行されていることを確認するためのチェックを行います)。

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_ID = '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 StartQueryHandler(webapp.RequestHandler):
  def post(self):
    query_string = self.request.get('query')
    jobCollection = bigquery_service.jobs()
    jobData = {
      'configuration': {
        'query': {
          'query': query_string,
        }
      }
    }
    try:
      insertResponse = jobCollection.insert(projectId=PROJECT_ID,
                                            body=jobData).execute()
      self.response.headers.add_header('content-type',
                                       'application/json',
                                       charset='utf-8')
      self.response.out.write(insertResponse)
    except:
      self.response.out.write('Error connecting to the BigQuery API')


class CheckQueryHandler(webapp.RequestHandler):
  def get(self, job_id):
    query_job = bigquery_service.jobs()
    try:
      queryReply = query_job.getQueryResults(projectId=PROJECT_ID,
                                             jobId=job_id).execute()
      self.response.headers.add_header('content-type',
                                       'application/json',
                                       charset='utf-8')
      self.response.out.write(queryReply)
    except:
      self.response.out.write('Error connecting to the BigQuery API')


application = webapp.WSGIApplication(
                                     [('/startquery(.*)', StartQueryHandler),
                                     ('/checkquery/(.*)', CheckQueryHandler)],
                                     debug=True)

def main():
  run_wsgi_app(application)

if __name__ == "__main__":
  main()
于 2012-08-14T16:28:04.557 に答える