无法使用 octokit 连接到 Github 帐户

Cannot connect to Github account using octokit

我无法连接到 GitHub 并无法使用“octokit”获取我的帐户凭据 gem。

client = Octokit::Client.new(
    client_id: ENV['GITHUB_CLIENT_ID'],
    client_secret: ENV['GITHUB_CLIENT_SECRET'],
 )

Gem 文件:

ruby '2.7.2'
gem 'rails', '~> 6.1.4', '>= 6.1.4.3'
gem "octokit", "~> 4.0"

错误信息:Octokit::Unauthorized (GET https://api.github.com/user: 401 - Requires authentication // See: https://docs.github.com/rest/reference/users#get-the-authenticated-user)

我遇到了同样的问题。 我是这样解决问题的:

client.user(ENV['GITHUB_LOGIN'], :headers => { "X-GitHub-OTP" => "2fa-token"})

如果您没有 ENV['GITHUB_LOGIN'],只需输入 Github 用户名

client.user('codescaptain', :headers => { "X-GitHub-OTP" => "2fa-token"})