Last Updated: November 06, 2018
· Khor

Using OAuth to Share Post Or Link on LinkedIn


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.

Code Example

You can test this snippet by trying to login with your LinkedIn account, or tweak it without requiring any configuration, coding, etc.

Code Explanation


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




$('#linkedin-button').on('click', function() {
// Initialize with your app public key
  OAuth.popup('linkedin2').then(linkedin => {{
      url: "/v1/people/~/shares?format=json",
      data: JSON.stringify({
        "comment": "Hello world!",
        "visibility": {
          "code": "anyone"
      headers: {
         "x-li-format": "json",
         "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 post or 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 account
  5. Link your LinkedIn app with by pasting your LinkedIn app client id and client secret into
  6. Copy the OAuth javascript snippet ( on to your web page


Use OAuth to share a post or link on LinkedIn: