I want to obtain the list of files on a Github repo. I followed this answer but I noticed that sometimes I have a HTTP 403 error. For example, if I run the following code:
library(httr)
for (i in 1:10) {
req <- GET("https://api.github.com/repos/etiennebacher/tidytuesday/git/trees/master?recursive=1")
stop_for_status(req)
}
> Error: Forbidden (HTTP 403).
(Note that I don't actually want to run this GET request 10 times, it's just the easiest way I found to simulate my problem. )
Searching a bit online, I found this answer that explains that the Github API requires the GitHub username, or the name of the application, for the User-Agent
header value of the request.
But adding user_agent("etiennebacher")
in GET()
doesn't change anything. How should I specify the user agent in this case?
Also asked on RStudio Community