LinkedIn Integration with v2 in Android using Rest API

Aryan Dhankar
WalkInTheCode
Published in
3 min readJul 25, 2019

Who should read?

if you are trying to integrate Linkedin login in 2019 and you have no clue where to go, then this article is for you. Here I will help to integrate Linkedin sign in step by step.

Benefits of this post

  • You can email id of the member.
  • You can also fetch profile image
  • You can also fetch country, Locale of the member
  • easy to integrate

Note:-

Now LinkedIn does not support TLS 1.0. You must use TLS 1.1 or 1.2 when calling LinkedIn APIs. All API requests to api.linkedin.com must be made over HTTPS. Calls made over HTTP will fail.

Step 1:-Application Creation

So first we have to create an Application on LinkedIn, so that go to My Apps, now click on Create App button. This will redirect you on the Crete App page where you have to fill all the details, as per your requirement and the hit on create app button, your app will be created with a Client ID and Client Secret.

Authorizing Permissions

According to LinkedIn’s permissions page, there are two kinds:

  • Member Authorization: Your application works with member account data to make requests on their behalf.
  • Application Authorization: Your application accesses LinkedIn APIs that are not member specific.

As we see in the below image, we can have your Client ID and Client Secret from Auth Section.

Step 2:-Create Authentication Url( Authenticating Members)

New members logging in to your service for the first time will need to follow the Authenticating with OAuth 2.0 Guide. When requesting an authorization code in Step 2 of the OAuth 2.0 Guide, make sure to request the r_liteprofile and/or r_emailaddress scopes!

Url format:- https://www.linkedin.com/oauth/v2/authorization?response_type=code&client_id=YOUR_CLIENT_ID&redirect_uri=YOUR_REDIRECT_URL&state=aRandomString&scope=r_liteprofile%20r_emailaddress%20w_member_social

Original url-> https://www.linkedin.com/oauth/v2/authorization

Parameters:

  • response_type -> when have to pass “code” in this field
  • client_id -> your client id from LinkedIn app.
  • redirect_uri -> here you have to create your own URI, so that when we will get our auth token, we will be redirected to this URI.
  • state -> it could be any random string, example XYZ.
  • scope -> This is recommended by Linkedin itself if you want to get the profile information of the user. So pass this “r_liteprofile%20r_emailaddress%20w_member_social” in scope parameter. for more info about the scope, you can read from here.

Step 3:-Get Authentication code

Now we have to load this URL in Webview and it will return you a code called authentication code. we will get it in the overridden method of Webview i.e

here we will get authorization code— String authorizationToken = uri.getQueryParameter(RESPONSE_TYPE_VALUE);

Step 4:-Create Access Token Url and get access token

after getting authorization code we have to get access token. for that, we have to create access token url as we can see in the above code

//Generate URL for requesting Access Token

String accessTokenUrl = getAccessTokenUrl(authorizationToken);

now we have to hit this url and in response, we will get our access token. I am calling PostRequestAsyncTask to hit this url like this…

Step 5:- Get Profile Information of user, using Access Token

Now we have to get member information so for that I have called GetProfileRequestAsyncTask to fetch data. I am calling below method from my async task.

  • Note -> to fetch email id of user we have a separate method sendGetRequestForEmail(), you can see its code below

Hurray!! now we have complete profile information of the user.

Below I have written the all above code in single Activity.

If you face any problem in integration feel free to contact me

If you like my hard work and effort, you can do one clap, two claps or maybe forty…

You can also find me on...

GitHub, Facebook, Quora, Twitter

--

--