LinkedIn API — OAuth 2.0 Access Token
Tags: linkedin
Published: 2022-06-07 03:49:22

---
title: LinkedIn API — OAuth 2.0 Access Token
published: true
date: 2022-04-22 04:15:00 UTC
tags: LinkedIn
cover_image: https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y398rzejg6ue2iqbsyau.jpeg
canonical_url: https://anlisha.com.np/blog/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 [_Developer Portal_](https://www.linkedin.com/developers/apps/new), specify App name, enter the LinkedIn Page of the company which will be associated with the application, upload logo and publish.

_Note: It is required to associate the app with a LinkedIn Company Page. The company selected will function as the publisher of the app._

![](https://anlisha.com.np/blog/wp-content/uploads/2022/05/1_N-A0W3QXp04nyUWQGva0sA.png)

**Step 2 — Request Application Verification**

Go to _Settings_ tab, select _Verify_ button next to the company associated with the app. Click the _Generate URL_ 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 _Verified_ in _Settings_ tab. The link will only expire earlier than 30 days if Page admin clicks _Deny_ in the request.

![](https://anlisha.com.np/blog/wp-content/uploads/2022/05/1_MbzL73g3TVBBcDwLtw2h1g.png)

![](https://anlisha.com.np/blog/wp-content/uploads/2022/05/1_qUw-Vex-ehICKd3pxBI2tQ.png)

**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.

![](https://anlisha.com.np/blog/wp-content/uploads/2022/05/1_K854eeZZWFA6NzHTydmnNg.png)

**Step 4— Application Credentials and Redirect URL**

Next click the _Auth_ tab to view application credentials i.e _Client ID_ and _Client Secret_.

Under _OAuth 2.0 settings, _we need to specify _Authorized redirect URLs_. Since we’re using Postman to get access token, we’ll add the Postman callback URL ‘_https://oauth.pstmn.io/v1/callback_’ to the list.

_Note: Please note Client ID_ and _Client Secret for later use._

![](https://anlisha.com.np/blog/wp-content/uploads/2022/05/1_UHbOMcnb8zm4HnRAZ8YKJQ.png)

**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.

![](https://anlisha.com.np/blog/wp-content/uploads/2022/05/1_RFeyZs1OqagAuKgdh3CTDQ.png)

Click the _Products_ tab and apply to _Marketing Developer Platform_, _Share on LinkedIn_ and _Sign in with LinkedIn_.

![](https://anlisha.com.np/blog/wp-content/uploads/2022/05/1_80ZRFYXRRy5R4guGYko5gg.png)

Complete the _MDP_ access form under _Products > Marketing Developer Platform_. A confirmation email is received when the application has been reviewed.

![](https://anlisha.com.np/blog/wp-content/uploads/2022/05/1_Gw2JFbr1N0xlg0n8IVjmMA.png)

Check the OAuth 2.0 scopes for the application now that products are added. _Sign in with LinkedIn_ product gives access to `r_liteprofile` and `r_emailaddress` scopes. _Share on LinkedIn_ product gives access to `w_member_social` scope. Remaining scopes are obtained from _Marketing Developer Platform _product_._

![](https://anlisha.com.np/blog/wp-content/uploads/2022/05/1_QhSGKTwwxpS0tHHCaBC8OQ.png)

**Step 6— Get Access Token via Postman**

Open _Postman, _Create _New Request _and_ _Click _Authorization_ Tab. Select _Type_ as _OAuth 2.0_. Fill in the given details:

- Token Name : `{provide token name}`
- Grant Type : `Authorization Code`
- Callback URL: `https://oauth.pstmn.io/v1/callback`
- Auth URL : `https://www.linkedin.com/oauth/v2/authorization`
- Access Token URL : `https://www.linkedin.com/oauth/v2/accessToken`
- Client ID : `{provide Client ID}`
- Client Secret : `{provide Client Secret}`
- Scope : `r_basicprofile, r_liteprofile, r_emailaddress, w_member_social, r_organization_social, rw_organization_admin, w_organization_social`
- State : `{provide a unique string value}`
- Client Authentication: `Send client credentials in body`

![](https://anlisha.com.np/blog/wp-content/uploads/2022/05/1_wPQ1XzsDGtn5vFMwac4gUg.png)

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

![](https://anlisha.com.np/blog/wp-content/uploads/2022/05/1_4d6Vqv7ikLwcaB-d8Q2utA.png)

Postman will display the access token to be used for testing. Choose _Use Token_ 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 _Admin_.

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 `https://www.linkedin.com/company/8681905/admin/`, 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 _Content admin_ role. Skip these steps if not required.

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

![](https://anlisha.com.np/blog/wp-content/uploads/2022/05/1_p0mrpCPVPpn-M8TA9cqmWg.png)

![](https://anlisha.com.np/blog/wp-content/uploads/2022/05/1_e1_8s3D2yNU1Tdr77G3sqQ.png)

**Dependencies:**

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

**References:**

[Getting Access to LinkedIn APIs – LinkedInThe LinkedIn API uses OAuth 2.0 for user authorization and API authentication. Applications must be authorized and…docs.microsoft.com](https://docs.microsoft.com/en-us/linkedin/shared/authentication/getting-access)

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!

The post [LinkedIn API — OAuth 2.0 Access Token](https://anlisha.com.np/blog/linkedin-api-oauth-2-0-access-token/) first appeared on [Anlisha Maharjan](https://anlisha.com.np/blog).