tidyverse / googledrive

Google Drive R API
https://googledrive.tidyverse.org/
Other
322 stars 47 forks source link

Error in `drive_auth()`: ! Can't get Google credentials. drive_auth working with console but not working from terminal or when scheduled #424

Closed naveenbussari closed 1 year ago

naveenbussari commented 1 year ago

Hi @jennybc , I am using rstudio-server, community version, installed on ubuntu 20.04. I am running an R script which reads an excel file. I have done the authentication and tokens are generated. I am using googledrive and googlesheets4 libraries.

`library(gargle)
library(cronR)
library(googlesheets4)
library(googledrive)

options(gargle_oath_cache = "~/.cache/gargle",
        gargle_oauth_email = "bussari.xxxxxx.com",
        use_oob = TRUE)

googledrive::drive_auth(email = "bussari.xxxxxx.com",
                        cache = "~/.cache/gargle",
                        use_oob = TRUE)

googlesheets4::gs4_auth(email = "bussari.xxxxxx.com",
                        cache = "~/.cache/gargle",
                        use_oob = TRUE)

x <-read_sheet('https://docs.google.com/spreadsheets/d/1VWS3hbSP6Q5Q25YG16dqgBAejy_eojYzN_V-2Q9epFk/edit#gid=0')

x

`

When I run the job manually from console, it runs fine and gives desired output. But i face issue when I run from terminal, it return an error

`Attaching package: ‘googlesheets4’
The following object is masked from ‘package:gargle’:
    request_make
Attaching package: ‘googledrive’
The following objects are masked from ‘package:googlesheets4’:
    request_generate, request_make
The following object is masked from ‘package:gargle’:
    request_make

Error in `googledrive::drive_auth()`:
! Can't get Google credentials.
ℹ Are you running googledrive in a non-interactive session? Consider:
• Call `drive_deauth()` to prevent the attempt to get credentials.
• Call `drive_auth()` directly with all necessary specifics.
ℹ See gargle's "Non-interactive auth" vignette for more details:
ℹ <https://gargle.r-lib.org/articles/non-interactive-auth.html>
Backtrace:
    ▆
 1. └─googledrive::drive_auth(...)
 2.   └─googledrive:::drive_abort(...)
 3.     └─cli::cli_abort(message = message, ..., .envir = .envir)
 4.       └─rlang::abort(...)
Execution halted`

FYI i followed #274 , #313 , #276 #284 and everything looks fine when run from console but fails when run through terminal.

Screenshot 2023-04-13 at 11 30 15 PM Screenshot 2023-04-13 at 11 31 38 PM
jennybc commented 1 year ago

I think there's a change in dev gargle that might help you. Can you install dev gargle and check?

https://github.com/r-lib/gargle/blob/f395d5f8c444f5460e61ab368144c7411d9011cd/NEWS.md?plain=1#L21

I will be releasing gargle soon.

naveenbussari commented 1 year ago

Thanks @jennybc for quick response.

It worked for me with the dev gargle v‘1.3.0.9000’. We are able to access google sheets from rstudio-server from both the console and terminal.

jennybc commented 1 year ago

Great! That will be released to CRAN soon.