Android LinkedIn Integration - Androhub

LinkedIn Integration Banner

Android LinkedIn Integration

Today we are going to learn how to integrate LinkedIn SDK in Android. By integrating LinkedIn into Android your user will be able to SingIn very quickly.

In this tutorial we are going to learn following features:

1. Authenticating with LinkedIn.

2. Fetching User Basic profile.

3. Sharing post to LinkedIn.

4. Opening current profile in LinkedIn app.

5. Opening others profile in LinkedIn app.

6. Log Out or clearing Logged In user session.

Tech Tip : Get an hassle-free remote access to your essential android apps on any device(PC/android/iOS) by loading Bluestacks onto a hosted xendesktop available at an affordable xendesktop cost. Learn more about Hosted QuickBooks and other hosted software products by visiting Apps4Rent.

VIDEO DEMO

Create App in LinkedIn

First step is to create an app in LinkedIn. To create app follow the below video:

Now to get Package Hash for created app use the below code:

Place the above code inside your Activity and call it in onCreate and it will give you Package Hash which you can use to put inside created App settings.

Adding Package Name and Package Hash
Adding Package Name and Package Hash

Download Mobile SDK for Android

Now download LinkedIn mobile SDK from this link. After downloading follow the below video to see how to add the LinkedIn SDK in android studio project.

Authentication with LinkedIn

After successfully adding SDK into your Android Studio project use the below code to authenticate account with LinkedIn.

Now to handle the authentication response in your app use the below code:

LinkedIn Authentication
LinkedIn Authentication

LinkedIn Authentication Flow

During the authentication process, there are several possible scenarios that could occur which result in different user experiences, based on:

  1. LinkedIn app is not installed on the mobile device : When LISessionManager.init() is called, the SDK will re-direct the user to the device’s play store page for the official LinkedIn application. Once user installed the app, the user will have to manually return to your application and restart the sign in process to continue.
  2. LinkedIn app is installed, user is not a LinkedIn member : When LISessionManager.init() is called, the LinkedIn application will launch and the user will be prompted to create a new LinkedIn account. The user will have to complete the account creation process (including email validation), manually return to your application and restart the sign in workflow to continue.
  3. LinkedIn app is installed, user is not signed in to LinkedIn : When LISessionManager.init() is called, the LinkedIn application will launch and users will be prompted to login with their LinkedIn credentials. Once validated, users will be presented with an authorisation screen outlining the name of your application and displaying the permissions that your app is requesting. If permission is granted, the user is returned to the Android Activity within your application that was provided in the argument to init(). A LISession object will now be available via LISessionManager.getSession() containing the access token required to perform further interactions with LinkedIn on the user’s behalf.
  4. LinkedIn app is installed, user is signed in to LinkedIn but has not authorised your app : When LISessionManager.init() is called, the LinkedIn application will launch and an authorisation screen outlining the name of your application and displaying the permissions that your app is requesting. If permission is granted, the user is returned to the Android Activity within your application that was provided in the argument to init(). A LISession object will now be available via LISessionManager.getSession() containing the access token required to perform further interactions with LinkedIn on the user’s behalf.
  5. LinkedIn app is installed, user is signed in and previously authorised your app : When LISessionManager.init() is called, the LinkedIn application will immediately return the user back to the specified Android Activity within your application. This will result in a brief screen flash as the device bounces out of your application, over to LinkedIn’s application, then immediately back to yours.
Device doesn't have LinkedIn App
Device doesn’t have LinkedIn App

Fetching Basic Profile Data

After successful authentication you will be able to fetch user basic profile data by calling LinkedIn REST APIs. For fetching basic profile data you can use below code :

To know more about basic profile parameters check this link.

Successful Fetching of Basic Profile Data
Successful Fetching of Basic Profile Data

Share on LinkedIn

To share some data to LinkedIn you have to call another REST Api by posting the sharing content to it. You can use below code to share content:

NOTE : LinkedIn doesn’t provide Image Sharing via Gallery or Camera to his application via SDK for this you can use Share Intent.

Successful Content Share
Successful Content Share

Cancel API Calls

If you want to cancel any API call which is in-progress use the below code:

Open Current Profile

This method will open the currently authenticated user’s LinkedIn profile directly within the official LinkedIn mobile application. Use the below code to fetch current profile :

Open Current Profile
Open Current Profile

Open Other Profile

This method will open a specific member profile within the official LinkedIn application. The memberID is a value that is unique to your particular LinkedIn application, representing a specific LinkedIn member. You can retrieve the current user’s id by making a REST API call to LinkedIn’s Profile API using the SDK’s API wrapper method.

Storing member ID values on your own server allows your application to direct users to the official LinkedIn profiles for any other users that have authorised your mobile application.

To handle DeepLinking callback add the below code in your Activity :

Logout

You can clear/logout user session when you don’t want it anymore by calling clearSession method like below:

Example

1. Create an App on LinkedIn and get update Package Name and Package Hash over there. To know how to create App check the video given above in article.

2. After creating app download LinkedIn SDK and add it into your Android Studio project. Download the LinkedIn SDK from here.

3. After adding LinkedIn SDK and syncing project open activity_main.xml and add the below code to it. In this layout there are several buttons to perform different tasks like : SignIn, Share, Open Profile page and Logout.

You can download LinkedIn official button image to place background to your Button. Download Button image from here.

4. Now open MainActivity.java and place the below code to it. In this class every feature is there that we discusses above like SignIn, Share, Open profile page and Logout.

5. Finally all done , now you can also add LinkedIn integration into your app.

Thanks. :)

 

12 Comments

Puneet
Wednesday, September 12th, 2018

Really Helpful

Nikita Prajapati
Wednesday, January 23rd, 2019

Hello,
I got this error while integrating LinkedIn
please help

Dr. Droid
Wednesday, January 23rd, 2019

Hi Nikita

What error you are getting can you share your error or logs.

Thanks

Khurram
Thursday, January 24th, 2019

I implemented this in my project and it was working fine, But suddenly few days back I am unable to sign in and getting access token equal to null. so whenever I fetch basic data onApiError function called.

Dr. Droid
Friday, January 25th, 2019

Hi Khurram,

For this you can again request login to user.

Thanks

Reddy
Friday, January 25th, 2019

is linked in sdk stopped ? not able to get logged user information

Dr. Droid
Friday, January 25th, 2019

Hi Reddy,

Yes it supports I think. If not then upgrade the SDK and try.

Thanks

Yıldırım TAM
Thursday, February 28th, 2019

I get “access toke is not to set” error” and I can not solve 🙁

Dr. Droid
Thursday, February 28th, 2019

Hi Yildirim,

Can you confirm that you have followed correct step to create app over LinkedIn and implementing it?

Thanks

Rahma
Thursday, February 28th, 2019

Hello ,Sir ,i use th code but i cant get the email address ,and i have error ,Accesstoken 0
Any help plz

Dr. Droid
Friday, March 1st, 2019

Hi Rahma,

I saw this error too and its due to that LinkedIn is returning NULL access token during SignIn.

LinkedIn moved the APIs to V2 so I will update you once the issue is fixed.

Thanks

Krutika chotara
Wednesday, March 27th, 2019

Hello i am getting
Auth Error :{
“errorCode”: “UNKNOWN_ERROR”,
“errorMessage”: “The passed in mobile identifier is invalid \”com.android_linkedin_integration_demo\””
}
Please help me to solve this

Post comment

Your email address will not be published. Required fields are marked *