使用 linkedin ruby gem 的 OAuth 问题
我正在尝试使用 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 文档:
需要额外授权: 访问令牌不正确 访问范围。
我仍然不明白为什么访问令牌没有正确的访问范围。
谢谢
I'm trying to connect to the linkedin API using the linkedin gem. I have the following code:
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)
When I run this code, every OAuth step works fine, except for the last one (authorize_from_request
). It gives the following error:
/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
Is my code missing something? What additional authorization is required?
According to the OAuth documentation:
additional_authorization_required: The
access token does not have the correct
access scopes.
Still I don't understand why the access token does not have the correct access scope.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
确保在使用之前删除 pin 尾部的空格
Make sure that you strip trailing whitespace from your pin before using it
另外,除了 Linkedin 开发者网络中已经配置的应用程序之外,在配置 Omniauth gem 初始化程序时,不要忘记设置正确的范围。
尝试添加类似于
Omniauth(或 Devise)初始化程序文件中现有配置行的内容。
Also, don't forget to set the proper scope when configuring the Omniauth gem initializer besides how the App is already configured in the Linkedin Developer Network.
Try adding something like
to the existing config line you might have in the Omniauth (or Devise) initializer file.