JQuery LinkedIn Button With Share Content

Prerequisite :

  1. Read Documentation at developer.linkedin.com
  2. Create an application follow developer @ linkedin
  3. Once application is created successfully, save your Client ID & Client Secret at secure location
  4. Post comments if you have any question on Prerequisite. Let jump on to topic

 

Create a  Custom Login Button :

HTML:

<!DOCTYPE html>
<html>

<head>
<meta charset=’utf-8′ />
</head>

<body>

<button type=”button” class=”btn btn-lg btn-info linkedinShareButton”>
<i class=”icon icon-linkedin”></i>
</button>

</body>

</html>

Looks like below:

linkedin.JPG

Jquery:

//platform.linkedin.com/in.js

// Setup an event listener to make an API call once auth is complete
function onLinkedInLoad() {
shareContent();
}

// Handle the successful return from the API call
function onSuccess(data) {
console.log(“onSuccess”);
console.log(data);
}

// Handle an error response from the API call
function onError(error) {
console.log(“error”);
console.log(error);
}

// Use the API call wrapper to share content on LinkedIn
function shareContent() {
// Build the JSON payload containing the content to be shared
var payload = {
“comment”: “Check out developer.linkedin.com! http://linkd.in/1FC2PyG“,
“visibility”: {
“code”: “anyone”
}
};

IN.API.Raw(“/people/~/shares?format=json”)
.method(“POST”)
.body(JSON.stringify(payload))
.result(onSuccess)
.error(onError);
}

$(document).on(“click”, “.linkedinShareButton”, function() {
IN.UI.Authorize().place();
IN.Event.on(IN, “auth”, onLinkedInLoad);
});

That it, Now go and check your post on LinkedIn.com, wait for couple of min to see your post on wall.

Let me know if you have any comments/ Suggestions and Appreciations 😉