Cuelogic Blog Icon
Cuelogic Career Icon
Home > Blog > Product Development > Web > Integration of LinkedIn API with OAuth 2.0

Integration of LinkedIn API with OAuth 2.0

Integration of LinkedIn API with OAuth 2.0

LinkedIn is one of the professional network. Number of users and companies are having their profile on LinkedIn. LinkedIn provides facility to mange profile from your own website using LinkedIn API. In this blog I have explained about how you can manage user profile as well as company profile using LinkedIn API with OAuth 2.

You can do following things using this API with PHP

  1. Manage Personal as well as Company profile information.
  2. Post or share updates, media and URL on LinkedIn.
  3. Fetch latest updates and post from Personal as well as Company profile.

Create LinkedIn Application

a. Company and Application information.

 

b. Your Contact information.

 

c. Application OAuth Keys and other information.

Once you've registered your LinkedIn app, you will get an API Key and Secret Key.

Note: Do not share your Secret Key.

How to use?

  1. 1. Download files from following link and paste that on your project.
  2. https://github.com/CuelogicTech/social-media-api/tree/LinkedIn
  3. 2. Update config.php fileOpen config.php from downloaded files and add your LinkedIn API key, Secrete key and Redirect URL.

I have listed out few frequently used functions from LinkedIn API class. You can check rest of the functions in LinkedIn.OAuth2.class.php file.

i) Get profile information

You can manage your personal as well as company profile information using following function.

$ObjLinkedIn = new LinkedInOAuth2($strAccessToken);

//To get personal profile information use getUserProfile function.
$ObjLinkedIn-> getUserProfile(USER ID);

//To get Company profile information use getCompany function.
$ObjLinkedIn-> getCompany(COMPANY ID);

 

ii) Get admin company pages

LinkedIn has provided getAdminCompanies function to get a list of all companies for the authenticated user which has admin access for those companies.

$ObjLinkedIn = new LinkedInOAuth2($strAccessToken);

// Method to get admin company pages
$ObjLinkedIn->getAdminCompanies ();

 

iii) Get profile updates

LinkedIn has provided getCompanyUpdates and getUserStatuses functions with which we can get a list of updates from user profile and company profile page.

$ObjLinkedIn = new LinkedInOAuth2($strAccessToken);//Start limit

$intStart = 0
//total number of updates display per page
$intCount = 20
$intCompanyId = COMPANY ID;
$intUserId = USER ID;

# Get Company page updates
$arrCompanyUpdates = $ObjLinkedIn->getCompanyUpdates($intCompanyId, $intStart, $intCount);

# Get User profile updates
$arrUSerProfileUpdates = $ObjLinkedin->getUserStatuses($intUserId, true, $intStart, $intCount);

 

iv) Post updates on LinkedIn company page

To post or share updates on LinkedIn you can use postToCompany function.

$ObjLinkedin = new LinkedInOAuth2($strOAuthToken);

# Post update on company page
$ObjLinkedin->postToCompany($intCompanyPageId, $strStatusMessage);