使用 linkedin ruby​​ gem 的 OAuth 问题

发布于 2024-11-14 07:33:17 字数 1251 浏览 1 评论 0原文

我正在尝试使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

遥远的绿洲 2024-11-21 07:33:17

确保在使用之前删除 pin 尾部的空格

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

puts client.authorize_from_request(rtoken, rsecret, pin)

Make sure that you strip trailing whitespace from your pin before using it

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

puts client.authorize_from_request(rtoken, rsecret, pin)
潦草背影 2024-11-21 07:33:17

另外,除了 Linkedin 开发者网络中已经配置的应用程序之外,在配置 Omniauth gem 初始化程序时,不要忘记设置正确的范围。

尝试添加类似于

:scope => 'r_fullprofile r_contactinfo r_emailaddress r_network'

Omniauth(或 Devise)初始化程序文件中现有配置行的内容。

provider :linkedin, ENV['LINKEDIN_KEY'], ENV['LINKEDIN_SECRET']

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

:scope => 'r_fullprofile r_contactinfo r_emailaddress r_network'

to the existing config line you might have in the Omniauth (or Devise) initializer file.

provider :linkedin, ENV['LINKEDIN_KEY'], ENV['LINKEDIN_SECRET']
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文