Linkedin Gem for Rails application

This is an example to use Linkedin Gem for using linkedin api inside your rails application

If you wanted to replace these things APP_CONFIG['api_key'] with your api keys you can also do that.

These are the things that are fetched by the linkedin gem using the api

first-name last-name headline positions educations skills

You can use @profile to fetch the values and use them according to your requirement.
class UserController < ApplicationController

 def login
   client =['api_key'], APP_CONFIG['secret_key'])
   request_token = client.request_token(:oauth_callback => "http://#{request.host_with_port}/user/authenticate_login")
   session[:rtoken] = request_token.token
   session[:rsecret] = request_token.secret
   redirect_to client.request_token.authorize_url 

  def profile 
  def authenticate_login
      client =['api_key'], APP_CONFIG['secret_key'])
      if session[:atoken].nil?
        pin = params[:oauth_verifier]
        atoken, asecret = client.authorize_from_request(session[:rtoken], session[:rsecret], pin)
        session[:atoken] = atoken
        session[:asecret] = asecret
       client.authorize_from_access(session[:atoken], session[:asecret])
 @profile = client.profile(:fields => %w(first-name last-name headline positions educations skills))
 @connections = client.connections
 render :action => :profile


Popular posts from this blog

Inserting and Moving elements inside Ruby Array

Find duplicate records in ServiceNow