Using OAuth2 to Share a link On Linkedin

If API is already deprecated, please report it by using this button

Purpose

Provide the easiest way (less than 15 lines of code) to use OAuth to share a post or link on a LinkedIn account on behalf of a LinkedIn user using Javascript.

Full Code to Share A Post or Link on LinkedIn

Here is the final code - a Javascript snippet that you can tweak, and play around with instantly without any coding, configuration, etc.

https://jsfiddle.net/fhgLe1aw/

Details of each part of the code:

HTML

<a id="linkedin-button" class="btn btn-block btn-social btn-vimeo">
  <i class="fa"></i> Share a Post with LinkedIn
</a>

CSS

None

JavaScript

$('#linkedin-button').on('click', function() {
// Initialize with your OAuth.io app public key
OAuth.initialize('txp2rKYpuKZXaaYC5kB-m13KnVE');
  OAuth.popup('linkedin2').then(linkedin => {
    // Get your linkedin profile id:
    linkedin.me().then(data => {
      let id = data.id;
      // Share a post
      linkedin.post({
        url: "/v2/ugcPosts",
        data: JSON.stringify({
            "author": `urn:li:person:${id}`,
            "lifecycleState": "PUBLISHED",
            "specificContent": {
                "com.linkedin.ugc.ShareContent": {
                    "shareCommentary": {
                        "text": "This post is shared using OAuth.io!"
                     },
                     "shareMediaCategory": "NONE"
                }
            },
            "visibility": {
                "com.linkedin.ugc.MemberNetworkVisibility": "PUBLIC"
            }
      }),
      headers: {
         "x-li-format": "json",
         "X-Restli-Protocol-Version": "2.0.0",
         "Content-Type": "application/json"
      }
    }).then(data => {
      console.log("success:", data);
      }).fail(err => { console.log("err:",err) });
  })
});
})

External Requirements

This Javascript code has external requirements:

Step-by-step Guide

Here is a summary of the steps to create this social button to share a Link on LinkedIn on a user's behalf using OAuth2:

  1. Create a LinkedIn account, if you do not have one
  2. Create an app on LinkedIn using this simple step-by-step guide
  3. Copy your LinkedIn app client id and client secret
  4. Signup for OAuth.io account
  5. Link your LinkedIn app with OAuth.io by pasting your LinkedIn app client id and client secret into OAuth.io
  6. Copy the OAuth javascript snippet (https://jsfiddle.net/ntu1qyg7/) on to your web page

Live example code for using OAuth to Share a link via Linkedin

Use Line OAuth to:

Use Apple OAuth to:

Use Meetup OAuth to:

Use Snapchat OAuth to:

Use Facebook OAuth to: