gpt4 book ai didi

ruby - 使用 linkedin ruby​​ gem 的 OAuth 问题

转载 作者:数据小太阳 更新时间:2023-10-29 08:53:53 25 4
gpt4 key购买 nike

我正在尝试使用 linkedin gem 连接到 linkedin API。我有以下代码:

require "rubygems"
require "yaml"
require "linkedin"

config = YAML.load_file("config.yml")

client = LinkedIn::Client.new(config["linkedin"]["consumer_key"], config["linkedin"]["consumer_secret"])
rtoken = client.request_token.token
rsecret = client.request_token.secret

puts client.request_token.authorize_url

puts "Access this URL get the PIN and paste it here:"
pin = gets

puts client.authorize_from_request(rtoken, rsecret, pin)

当我运行这段代码时,除了最后一步 (authorize_from_request) 之外,每个 OAuth 步骤都运行良好。它给出了以下错误:

/Library/Ruby/Gems/1.8/gems/oauth-0.4.4/lib/oauth/consumer.rb:181:in `request': additional_authorization_required (OAuth::Problem)
from /Library/Ruby/Gems/1.8/gems/oauth-0.4.4/lib/oauth/consumer.rb:197:in `token_request'
from /Library/Ruby/Gems/1.8/gems/oauth-0.4.4/lib/oauth/tokens/request_token.rb:18:in `get_access_token'
from /Library/Ruby/Gems/1.8/gems/linkedin-0.2.2/lib/linked_in/authorization_helpers.rb:28:in `authorize_from_request'
from linked_in.rb:17

我的代码是否遗漏了什么?需要什么额外的授权?

根据 OAuth 文档:

additional_authorization_required: The access token does not have the correct access scopes.

我仍然不明白为什么访问 token 没有正确的访问范围。

谢谢

最佳答案

确保在使用 pin 之前去除尾随空格

puts "Access this URL get the PIN and paste it here:"
pin = gets.strip

puts client.authorize_from_request(rtoken, rsecret, pin)

关于ruby - 使用 linkedin ruby​​ gem 的 OAuth 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6285659/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com