Updated 24 November 2017
OAuth is an open standard for authorization, commonly used as a way for Internet users to authorise websites or applications to access their information on other websites but without giving them the passwords. These days OAuth is considered as the safest way to authorise and to get the user data from another resource server.
There are several famous servers around the world ( Like Facebook, Google, Linkedin, Twitter etc. ) on which most of the users are registered and these servers can be used to share the user data to other apps.
In this blog, We will talk about getting user data from Linkedin’s server using OAuth. There are several APIs provided by Linkedin to communicate with their server and request the user data as per the requirement.
For getting started you need to first register your app at here and get your Authentication Keys ( client_id and client_secret )
NOTE : DO NOT share your Client Secret value with anyone !!!
After getting your Authentication Keys, you need to make a GET request to the Linkedin API with your client_id to get an authentication code.
The request may look like :
https://www.linkedin.com/oauth/v2/authorization?response_type=code&client_id=123456789&redirect_uri=https%3A%2F%2Fwww.example.com%2Fauth%2Flinkedin&state=987654321&scope=r_basicprofile
After making a successful authorization request, You will receive an authorization code and this authorization code is used to exchange access token form Linkedin server.
This time you need to make a POST request to get the access token.
The request may look like :
https://www.linkedin.com/oauth/v2/accessToken?grant_type=authorization_code&code=AQRpE2V0kVBfBKpMmoyT72VDsfT_CV6N7uVYUNNnp_Jc39lISSrlNnVfrysMzG-fsoo_wb2zdAOFupz_HzkSvvLe1wz1XQMt-b33yf1nWaNDSNyVGKE&client_id=81fdcyfxm5621c&redirect_uri=http://magento.webkul.com/Mobikul/auth/linkedin&client_secret=****************
After making a successful AccessToken request, You will receive an access token and its expiry time. This access token is used in the next request to get the user data.
To retrieve basic information, Your request may look like :
https://api.linkedin.com/v1/people/~?format=json
To retrieve specific information, Your request may look like :
https://api.linkedin.com/v1/people/~:(id,num-connections,picture-url)&format=json
NOTE : format=json is to get the response in json format otherwise it will give the response in XML format.
After the above request you will receive the user data and can use it as per the requirement.
Thank you very much, This is Vedesh Kumar signing off … : )
If you have more details or questions, you can reply to the received confirmation email.
Back to Home
Be the first to comment.