rauthenticationamazon-ec2google-sheets-apir-googlesheets

How to authenticate with googlesheets package in a head less environment(EC2 instance)?


Normally when I use googlesheets package on my desktop R studio, it puts me through a browser based authentication, where I select my Google account for authentication and it gets approved.I use the gs_ls() function for authentication.

Now I am trying to use the googlesheets package in R in my Amazon EC2 instance, which does not have a browser available. How do I go through the authentication process in this environment?


Solution

  • I found the solution to this question.

    What i basically did was published the Google sheet as a web page and set the access rights to public. If we do this we can access the google sheet without any browser based authentication. I used the following code-

    sheet_key='xxxxxxxxxxxxxxxxxxxx'
    sheetdata <- sheet_key %>%  gs_key(lookup = FALSE) %>% gs_read()
    

    Sheet key is basically the portion of url between /d and /edit

    https://docs.google.com/spreadsheets/d/xxxxxxxxxxxxxxxxxxxx/edit#gid=0