我正在尝试使用 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)
当我运行此代码时,每个 OAuth 步骤都工作正常,除了最后一个步骤 (authorize_from_request
)。它给出以下错误:
/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/