1
votes

Access to data from Google Drive from ipython notebook in Google Datalab returns:

Exception: accessDenied: Access Denied: BigQuery BigQuery: No OAuth token with Google Drive scope was found.

Tried running gcloud config solution in bq cmd query Google Sheet Table occur "Access Denied: BigQuery BigQuery: No OAuth token with Google Drive scope was found" Error

Solution does not work for datalab.

Only other thing i can think of is that I have more than one Google ID (outside of this project), so it is unable to connect the OAUTH from Google Drive to Google Datalab.

1
The problem is that Datalab uses a Compute Engine service account, which does not have the proper OAuth2 scopes to access Google Drive. The trouble is, I don't know if it's possible to grant those scopes to it.Tim Swast

1 Answers

1
votes

Though not elegant, you can always create your own credentials and pass to the BigQuery Query object:

import google.datalab
import google.datalab.bigquery as bq
from google.oauth2.service_account import Credentials

scopes = (
    'https://www.googleapis.com/auth/bigquery',
    'https://www.googleapis.com/auth/cloud-platform',
    'https://www.googleapis.com/auth/drive'
)
credentials = Credentials.from_service_account_file('service_account.json')
credentials = credentials.with_scopes(scopes)

context = google.datalab.Context("<project id>", credentials)

your_named_query.execute(context=context)

Where "your_named_query" is from a "%%bq query --name your_named_query" cell. You will also need to make sure that your service account is granted access to the appropriate Google Docs (e.g. by "Share"ing the doc with the service account email address).