You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

运行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)

    1. In RStudio, run: usethis::create_github_token()
    2. 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".
    3. Copy the token immediately—you won’t be able to view it again after leaving the page.
  • Set up the PAT in R

    1. Run: usethis::edit_r_environ() to open your .Renviron file.
    2. Add a line like: GITHUB_PAT=your_copied_token (replace your_copied_token with the actual token, no quotes needed).
    3. Save the file and restart RStudio to apply the changes.
  • 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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.12 08:42:45