tylertreat/BigQuery-Python

Build using google credentials

Opened this issue · 1 comments

It's possible to build a service using GoogleCredentials? I tried giving the GoogleCredentials as parameter, but it crashes when building the service:
service = build('bigquery', 'v2', http=http, discoveryServiceUrl=service_url)
I'm doing something like this:
get_client(project, credentials=GoogleCredentials.get_application_default(), private_key="private_key.json", readonly=False)
But I got:

oauth2client.client.AccessTokenRefreshError: invalid_scope: Empty or missing scope not allowed.

I just don't know if I'm doing something wrong or if I don't know how to use the lib/services correctly.. but I believe I need something like this
discovery.build('bigquery', 'v2', credentials=credentials)

This should work. Perhaps you need to do something like this?

from bigquery.client import BIGQUERY_SCOPE
credentials = GoogleCredentials.get_application_default()
scopes = BIGQUERY_SCOPE
credentials = credentials.create_scoped(scopes)

Looking closer at your example, if you're providing a private key file, you should use the private_key_file kwarg, not private_key which takes the key as a string. Also, if you're providing credentials, you shouldn't have to provide a private key.