繁体   English   中英

如何使用linkedin gem和omniauth获得更精细的LinkedIn用户信息?

[英]How do I get more granular LinkedIn user information using linkedin gem and omniauth?

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

来自user.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错误?

谢谢!

[编辑]好吧,找到了。 devise.rb字段定义错误。 (可能已经过时了,我使用了同样的东西,它是从某处复制的。)

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

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

访问用户信息ID的格式为:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM