LinkedIn API — OAuth 2.0 Access Token

LinkedIn API — OAuth 2.0 Access Token

Hi, on a recently worked project, we needed to fetch shares (posts) of company in LinkedIn. Thus, I write this step by step guide to access LinkedIn API.

The LinkedIn API uses OAuth 2.0 for user authorization and API authentication. Since we need access to Marketing APIs to fetch posts of company, we’ll follow Authorization Code Flow (3-legged authorization).

Step 1 — Register application in the LinkedIn Developer Portal

Create a new app in , specify App name, enter the LinkedIn Page of the company which will be associated with the application, upload logo and publish.

Register application in the LinkedIn Developer Portal

Step 2 — Request Application Verification

Go to tab, select button next to the company associated with the app. Click the button in the Company Verification pop-up. Copy the URL and send it to the Page admin for verification.

Page admin has 30 days to verify the app with the unique URL. Once the Page admin approves the request, the app will show in tab. The link will only expire earlier than 30 days if Page admin clicks in the request.

Verify the application
Verify Company

Step 3— Verify Application Request

As a Page admin when a unique URL is received requesting approval to associate the app with company Page; Clicking the URL will navigate to the Developer Portal. Sign in and the landing page will feature the request details; company page information, app information, and the requestor’s name. The request can either be approved or denied.

Once verification is complete, it cannot be undone. If the link is accessed after 30 days, the landing page will showcase an expired message and a new unique URL link must be generated.

Verify Application Request

Step 4— Application Credentials and Redirect URL

Next click the tab to view application credentials i.e and .

Under we need to specify . Since we’re using Postman to get access token, we’ll add the Postman callback URL ‘’ to the list.

and

Application Credentials and Redirect URL

Step 5— Setup OAuth 2.0 scopes

To fetch data through LinkedIn API we requires access to proper OAuth 2.0 scopes such as r_basicprofile, r_organization_social. These scopes are based on the products added in the application.

OAuth 2.0 scopes

Click the tab and apply to , and .

Products

Complete the access form under . A confirmation email is received when the application has been reviewed.

MDP

Check the OAuth 2.0 scopes for the application now that products are added. product gives access to r_liteprofile and r_emailaddress scopes. product gives access to w_member_social scope. Remaining scopes are obtained from product

OAuth 2.0 scopes

Step 6— Get Access Token via Postman

Open Create andClick Tab. Select as . Fill in the given details:

  • Token Name :
  • Grant Type :
  • Callback URL:
  • Auth URL :
  • Access Token URL :
  • Client ID :
  • Client Secret :
  • Scope :
  • State :
  • Client Authentication:
Access Token via Postman

Click on Postman will take us to the LinkedIn authorization page, where it is prompted to log into LinkedIn. Click to authorize the request. The prompt on the authorization page is dictated by the requested scopes in the previous step.

Get New Access Token

Postman will display the access token to be used for testing. Choose button to set this token.

Step 7— LinkedIn Find Shares By Owner API

Our application can now retrieve the collection of shares (posts) owned by a specific organization for which the authenticated member is an .

API Endpoint:

GET https://api.linkedin.com/v2/shares?q=owners&owners=urn:li:company:{id}&sortBy=LAST_MODIFIED&sharesPerOwner=1000&count=50&start=0&oauth2_access_token={ACCESS_TOKEN}

LinkedIn Company ID is a unique 6 to 9 digits long string of numbers. To find Company ID as a LinkedIn Page Admin, navigate to the Admin View of the LinkedIn Page from the All Pages or Home tab. The LinkedIn company ID is the numbers after “/company/” in the URL. For example, if the Admin URL for the LinkedIn Page is , the company ID is 8681905.

And this is it!

If you need to fetch shares (posts) of LinkedIn Company Page that doesn’t belong to you, then the Admin of that Company Page must add you as role. Skip these steps if not required.

As a Page Admin, access your LinkedIn Company Page Admin view. Click the dropdown at the top of the page and select . Click the button. Search the authenticated member and assign role as and Save.

Manage Page Admins
Add Page Admin

Dependencies:

  • For each company, the authenticated user must have a role in the company’s LinkedIn Page to fetch shares (posts) of the organization.
  • The app must have access to product and its scopes.

References:

If you enjoyed learning about LinkedIn API access flow then feel free to give this article a clap and follow to stay up to date with more articles! Thanks for reading!

--

--

Full-Stack Developer | Freelancer | https://anlisha.com.np

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store