Using Google Datalab, trying to import data from Google Drive

老子叫甜甜 提交于 2019-12-11 04:49:36

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!