运行devtools::source_gist时出现401无效凭证错误求助
Fixing GitHub API 401 Error for
devtools::source_gist The 401 authentication error happens because GitHub now requires authenticated requests to access gists via its API—even for public gists. Here's how to fix it:
Generate a GitHub Personal Access Token (PAT)
- In RStudio, run:
usethis::create_github_token() - This opens GitHub in your browser. Name the token (e.g., "R Gist Access"), check the gist scope under the "Gist" section, then click "Generate token".
- Copy the token immediately—you won’t be able to view it again after leaving the page.
- In RStudio, run:
Set up the PAT in R
- Run:
usethis::edit_r_environ()to open your .Renviron file. - Add a line like:
GITHUB_PAT=your_copied_token(replaceyour_copied_tokenwith the actual token, no quotes needed). - Save the file and restart RStudio to apply the changes.
- Run:
Test your command again
Execute your original code:devtools::source_gist("00772ccea2dd0b0f1745", filename = "001_bag_functions.r")
If you already have a PAT, confirm it hasn’t expired and includes the gist scope. You can check this in your GitHub account under Settings > Developer settings > Personal access tokens.
内容的提问来源于stack exchange,提问作者sofia
相关产品推荐
相关产品推荐

