我正在尝试使用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:访问令牌没有正确的访问范围。
不过,我还是不明白为什么访问令牌没有正确的访问范围。
谢谢
发布于 2011-07-06 17:09:30
使用前一定要从引脚上去掉尾随空格。
puts "Access this URL get the PIN and paste it here:"
pin = gets.strip
puts client.authorize_from_request(rtoken, rsecret, pin)
发布于 2015-03-02 00:46:32
此外,除了在Linkedin开发人员网络中已经配置了应用程序之外,不要忘记在配置Omniauth初始化器时设置适当的范围。
尝试添加这样的东西
:scope => 'r_fullprofile r_contactinfo r_emailaddress r_network'
到Omniauth (或Devise)初始化器文件中的现有配置行。
provider :linkedin, ENV['LINKEDIN_KEY'], ENV['LINKEDIN_SECRET']
https://stackoverflow.com/questions/6285659
复制相似问题