In this article, we will show you how to post text in the LinkedIn timeline through LinkedIn developer app. Follow these steps:
Step-1:
Create an ASP.Net solution, add an aspx page, copy the
localhost URL.
Step-2:
Log in to your LinkedIn account. Then open the https://developer.linkedin.com/
link.
Step-3:
Click on MyApp then Create an application. Then create a new
application form will appear. Fill all the fields and submit them, then the
application will create.
Step-4:
Now check all the Default Application Permission, and give
the localhost link in Authorization Redirect URLs and click on add. Then click
on update.
Step-5:
From the left side, the menu bar goto JavaScript and set the
Valid SDK Domain (your localhost URL) and click on add. Then
Step-6:
Then write the following script in your aspx page.
<html>
<head runat="server">
<title></title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script>
<script type="text/javascript" src="//platform.linkedin.com/in.js">
api_key: Your API Key(ClientId)
authorize: true
onLoad: onLinkedInLoad
</script>
<script type="text/javascript">
// Setup an event listener to make an API call once auth is complete
function onLinkedInLoad() {
IN.Event.on(IN, "auth", shareContent);
}
// Handle the successful return from the API call
function onSuccess(data) {
console.log(data);
}
// Handle an error response from the API call
function onError(error) {
console.log(error);
}
// Use the API call wrapper to share content on LinkedIn
function shareContent() {
debugger;
var msg = document.getElementById('<%=TextBox1.ClientID%>').value;
// Build the JSON payload containing the content to be shared
var payload = {
"comment": msg ,
"visibility": {
"code": "anyone"
}
};
IN.API.Raw("/people/~/shares?format=json")
.method("POST")
.body(JSON.stringify(payload))
.result(onSuccess)
.error(onError);
}
</script>
</head> <body>
<form id="form1" runat="server">
<div>
<script type="in/Login"></script>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Click Here" OnClientClick="shareContent()" />
</div>
</form>
</body>
</html>
Related Links:
post text and image in Facebook
0 Comments