问题
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:
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).
来源:https://stackoverflow.com/questions/46370970/using-google-datalab-trying-to-import-data-from-google-drive