首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >使用linkedin红宝石的OAuth问题

使用linkedin红宝石的OAuth问题
EN

Stack Overflow用户
提问于 2011-06-08 21:45:31
回答 2查看 1.1K关注 0票数 2

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

代码语言:javascript
运行
复制
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)。它给出了以下错误:

代码语言:javascript
运行
复制
/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:访问令牌没有正确的访问范围。

不过,我还是不明白为什么访问令牌没有正确的访问范围。

谢谢

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2011-07-06 17:09:30

使用前一定要从引脚上去掉尾随空格。

代码语言:javascript
运行
复制
puts "Access this URL get the PIN and paste it here:"
pin = gets.strip

puts client.authorize_from_request(rtoken, rsecret, pin)
票数 3
EN

Stack Overflow用户

发布于 2015-03-02 00:46:32

此外,除了在Linkedin开发人员网络中已经配置了应用程序之外,不要忘记在配置Omniauth初始化器时设置适当的范围。

尝试添加这样的东西

代码语言:javascript
运行
复制
:scope => 'r_fullprofile r_contactinfo r_emailaddress r_network'

到Omniauth (或Devise)初始化器文件中的现有配置行。

代码语言:javascript
运行
复制
provider :linkedin, ENV['LINKEDIN_KEY'], ENV['LINKEDIN_SECRET']
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6285659

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档