11

I have a table connect with Google Sheet, use WebUI query this table success, but if I use bq cmd query, It will echo error msg:

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

Karl Lin
  • 307
  • 4
  • 16
  • just do a little search here in SO - there are quite a number of exact same questions!! have you tried? – Mikhail Berlyant Sep 13 '17 at 14:46
  • @MikhailBerlyant Yes, I try to search, and add --enable-gdrive-access into gcloud login, but it doesn't work, so I come to SO ask. – Karl Lin Sep 14 '17 at 12:07

4 Answers4

10

I presume you are using bq command line tool which comes with Cloud SDK.

To use bq you had to procure credentials, most likely you used

gcloud auth login

By default these credentials do not get drive scope. You have to explicitly request it via

gcloud auth login --enable-gdrive-access

Now running bq to access Google Drive data should work.


From the comments: for some people, it seems to be necessary to run

gcloud auth revoke

before logging in again. (Deleting ~/.config/gcloud would also work, but is probably overkill.)

Thomas
  • 174,939
  • 50
  • 355
  • 478
cherba
  • 8,681
  • 3
  • 27
  • 34
  • 3
    thanks! But I try this way and It doesn't work for me. – Karl Lin Sep 14 '17 at 12:07
  • 6
    Hi, I know what happen, before gcloud auth login --enable-gdrive-access, I need delete ~/.config/gcloud folder, thanks!! – Karl Lin Sep 14 '17 at 12:32
  • Unless you have corrupted your gcloud configuration this step of deleting the folder should not be necessary. Glad it worked for you. – cherba Sep 14 '17 at 17:58
  • 1
    how to enable drive access for service account? – MJK Nov 03 '17 at 14:14
  • @MLK, it depends on your circumstances, what type of application and where you trying to use service account. See some info https://developers.google.com/identity/protocols/OAuth2ServiceAccount#creatinganaccount. If you still have questions it would warrant a separate StackOverflow question. – cherba Nov 04 '17 at 14:52
  • 1
    I also needed to delete `~/.config/gcloud` and then re-run for this to work properly. – ryantuck Nov 22 '17 at 20:39
  • @MLK Assuming the service account is attached to a GCE instance, than you can do this locally and then restart your instance: ```gcloud beta compute instances set-scopes [INSTANCE_NAME] \ --service-account [SERVICE_ACCOUNT_EMAIL] \ --scopes https://www.googleapis.com/auth/cloud-platform, https://www.googleapis.com/auth/drive ``` – Jas Dec 13 '17 at 21:11
  • @cherba I tried this and also had to remove the directory before it would work, pretty sure I haven't corrupted the directory. Seems pretty common for other people too. It would be preferable not to remove the directory but not sure what part of it is missing the `OAuth token with Google Drive scope` – Davos Feb 05 '19 at 03:36
  • 1
    It seems necessary to first execute `gcloud auth revoke` and then `gcloud auth login --enable-gdrive-access` – sinmetal Feb 17 '19 at 12:05
  • I had to delete the `.config/gcloud` folder, then `gcloud auth login --enable-gdrive-access --update-adc` - without the last flag for some reason the `application_default_credentials.json` file wasn't appearing.. – magicrebirth Jun 11 '20 at 13:33
4

Chances are the 'https://www.googleapis.com/auth/drive.readonly' scope is missing in the credentials of your request.

For details, see: Credentials Error when integrating Google Drive with

1

Run auth revoke then auth login if only the latter doesn't work.

gcloud auth revoke
gcloud auth login --enable-gdrive-access
Yoichi Tagaya
  • 4,547
  • 2
  • 27
  • 38
0

Hi, I know what happen, before gcloud auth login --enable-gdrive-access, I need delete ~/.config/gcloud folder, thanks!! – Karl Lin Sep 14 '17 at 12:32

Here's the complete answer based on Karl Lin's comment to the accepted answer.

rm -rf ~/.config/gcloud 
gcloud auth login --enable-gdrive-access

I needed to delete ~/.config/gcloud or it won't work.

logan
  • 3,416
  • 1
  • 33
  • 45