【问题标题】:How do I get more granular LinkedIn user information using linkedin gem and omniauth?如何使用linkedin gem 和omniauth 获取更详细的LinkedIn 用户信息?
【发布时间】:2014-01-21 22:45:39
【问题描述】:

我想从他们的 LinkedIn 个人资料(公司名称、职务等)中获取用户的职位信息,但除了基本的个人资料信息(id、姓名、电子邮件、标题和图片)之外,我什么也得不到。我猜这只是一个语法问题,因为我在用户身份验证后请求访问所有字段。

来自用户.rb

    def self.from_omniauth(auth)
      where(auth.slice(:provider, :uid)).first_or_initialize.tap do |user|
        user.provider = auth.provider
        user.uid = auth.uid
        user.name = auth.info.name
        user.email = auth.info.email
        user.headline = auth.info.headline
        **user.company = auth.info.company**
        user.avatar = auth.info.image
        user.password = SecureRandom.urlsafe_base64(n=6)
        user.save!    
    end  

来自devise.rb

  config.omniauth :linkedin, "abcdefghijk", "abcdefghijk", 
  # :scope => 'r_basicprofile r_emailaddress rw_nus r_fullprofile r_contactinfo r_network rw_company_admin',
  # :fields =>
  :scope => 'r_basicprofile r_emailaddress rw_nus r_fullprofile r_contactinfo r_network rw_company_admin', 
  :fields => ["id", "email-address", "first-name", "last-name", 
                  "headline", "industry", "picture-url", "public-profile-url", 
                  "location", "connections", "skills", "date-of-birth", "phone-numbers",        
                  "educations", "three-current-positions" ]

我是否需要在 devise.rb 中添加字段,还是我是个白痴并格式化 user.company = auth.info.company 错误?

谢谢!

【问题讨论】:

  • 你能得到公司 ID(用户是管理员)吗?

标签: ruby-on-rails api devise linkedin omniauth


【解决方案1】:

[编辑] 好的,找到了。 devise.rb 字段定义错误。 (可能已经过时了,我用的是同一个,而且是从某个地方复制过来的。)

现在正确的名称只是“职位”,而不是“三个当前职位”

之后,auth.extra.info.positions 变为可用(使用这些参数:https://developer.linkedin.com/docs/fields/positions

【讨论】:

    【解决方案2】:

    获取用户信息id的格式为:

    user.name = auth["info"]["name"]
    

    【讨论】:

    • 不回答 OP 的问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多