How to use linkedin api in Rails applications?

LinkedIn actually provides 2 APIs:

  • The JavaScript API is a rich client library enabling you to build dynamic applications in the web browser. Use OAuth 2 to easily authorize users via the “Sign In with LinkedIn” button, access LinkedIn data with native objects, and interact with Plugins.
  • The REST API provides a simple, consistent representation of people, companies, jobs, and the interactions and relationships between them. Our query language lets you read data in XML and JSON at the granularity and aggregation that you choose. Use OAuth 1.0a to authorize users and begin making REST API calls using any programming language.

1. Initialize your linkedin api key and secret key

Linked in api key can be obtained from http://developer.linkedin.com/

  • linkedin_api_key = ” YOUR LINKEDIN API KEY”
  • secret_key = “YOUR LINKEDIN API SECRET”

2. Setting your callback:

callback_url = ‘http://localhost:3000/linkedin_callback’

3. Create oauth object

oauth = LinkedIn::Oauth.new(linkedin_api_key, linkedin_secret)

4. Request authorize url

oauth.request_token.authorize_url

=> “https://api.linkedin.com/uas/oauth/authorize?oauth_token=53bc5779-75fb-4a82-915c-a33dba1dddf2″

Open the link in your browser as redirection url for user to do authorization process, if user authorize it we will get params[:oauth_verifier] in our “callback_url”, use it to authorize from request.

for example:

http://localhost:3000/linkedin_callback?oauth_token=94145e28-2d4d-4d55-856d-c5e791334e09&oauth_verifier=00883

oauth_verifier = “00883″

authorize using oauth verifier and token

oauth.authorize_from_request(oauth.request_token.token, oauth.request_token.secret, oauth_verifier)

create linkedin api object

linkedin = LinkedIn::Base.new(oauth)

 
For any rails development & consulting services Hire rails developer from RailsCarma

This website uses cookies to ensure you get the best experience on our website.