Get a token to authorize googlesheets4 in crontab


As someone unfamiliar with authorizations on googlesheets, I'm quite confused with creating a token that I can use to authorize. Here is what's happening:

I've set up a public (anyone with the link can edit) googlesheet where I hold tweet data. I've created a R script that pulls data from Twitter using rtweet and then uses sheet_append to append this data to the googlesheet:

# Load packages

# Search for 1000 tweets, excluding retweets
# 400 ~ 600 Tweets on average per day. Safe to search for 1000 tweets and then filter out for each date.
rt <- search_tweets("#rstats", n = 1000, include_rts = FALSE) %>% 
  # Extract out dates
  mutate(created_at = lubridate::date(created_at)) %>% 
  # Filter for today's tweets
  filter(created_at == Sys.Date())

# Append tweet data to Googlesheets
sheet_append(ss = "",
            data = rt,
            sheet = "Sheet1")

I imagine that this won't work in a cronjob because it'd require authentication in a popup browser, when I run search_tweets.

When I run sheet_append, this message pops up:

A few years ago, when the googlesheets package was alive, I used to just create a token (previous_token.rds) and run gs_auth(token = "previous_token.rds") .

I'd like to do the same with googlesheets4 package, but I can't figure out how. Could someone instruct me on how to create a token and authorize in googlesheets4 package, as I did with the googlesheets package?

Thank you!

I'll answer my own question:

Run this line before sheet_append

gs4_auth(email = "")

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.