How to Use linkedin api in Rails applications?


LinkedIn Provides Two 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)

Source: RailsCarma.com

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s