[英]How to get linkedin profile information in rails?
Hi i am using linkedin gem to connect with linkedin from rails.您好我正在使用 linkedin gem 从 rails 连接 linkedin。 this what is my controller.
这是我的 controller。
class LoginsController < ApplicationController
helper_method :current_user
def show
end
def create
request_token = consumer.get_request_token(:oauth_callback => callback_login_url)
Rails.cache.write(request_token.token, request_token.secret)
redirect_to request_token.authorize_url
end
def callback
request_token = OAuth::RequestToken.new(consumer, params[:oauth_token], Rails.cache.read(params[:oauth_token]))
access_token = request_token.get_access_token(:oauth_verifier => params[:oauth_verifier])
session[:access_token] = access_token.token
session[:access_token_secret] = access_token.secret
redirect_to :action => :show
end
def logout
reset_session
redirect_to :action => :show
end
private
CONSUMER_KEY = {
:key => "ddddd",
:secret => "eeeeeeeeee"
}
CONSUMER_OPTIONS = { :site => 'https://api.linkedin.com',
:authorize_path => '/uas/oauth/authorize',
:request_token_path => '/uas/oauth/requestToken',
:access_token_path => '/uas/oauth/accessToken' }
def consumer
@consumer ||= OAuth::Consumer.new( CONSUMER_KEY[:key], CONSUMER_KEY[:secret], CONSUMER_OPTIONS)
end
def access_token
if session[:access_token]
@access_token ||= OAuth::AccessToken.new(consumer, session[:access_token], session[:access_token_secret])
end
end
def current_user
if access_token
@current_user ||= JSON.parse(access_token.get('http://api.linkedin.com/v1/people/~', 'x-li-format' => 'json').body)
end
@current_user
end
end
and this is what is my view:这就是我的观点:
<% if current_user %>
Welcome to Lovelinked , <%=link_to current_user['firstName'], current_user['siteStandardProfileRequest']['url'] %>
<%=link_to current_user['lastName'], current_user['siteStandardProfileRequest']['url'] %>
<%=button_to "Sign Out", logout_login_path, :method => :get %>
<% else %>
Sign in with LinkedIn
<%=button_to "Sign In", login_path, :method => :post %>
<% end %>
I am able to get firstName and lastName and passed parameters like images_url and location but it is not working, How to get these informations also educations currentcompanyname etc.我能够获取 firstName 和 lastName 并传递 images_url 和 location 等参数,但它不起作用,如何获取这些信息以及教育 currentcompanyname 等。
Please help me i googled but could not get correct information.请帮助我用谷歌搜索但无法获得正确的信息。
try gem linkedin-scraper
https://github.com/yatishmehta27/linkedin-scraper试试 gem
linkedin-scraper
https://github.com/yatishmehta27/linkedin-scraper
Using the 'linkedin' gem you can do the following to get the information you are looking for returned as an array of strings.使用“linkedin”gem,您可以执行以下操作以获取您要查找的信息作为字符串数组返回。
user = client.profile(:fields => %w(positions))
companies = user.positions.all.map{|t| t.company}
# And if you want the most recent company it can be accessed via companies[0]
All of this information was found at https://github.com/pengwynn/linkedin/blob/master/examples/profile.rb所有这些信息都可以在https://github.com/pengwynn/linkedin/blob/master/examples/profile.rb找到
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.