Tuesday 21 March 2017

Posting text in LinkedIn

Posting text in LinkedIn:

Step-1:

Create an ASP.Net solution, add an aspx page, copy the local host URL.

Step-2:

Login to your LinkedIn account. Then open the https://developer.linkedin.com/ link.

Step-3:

Click on MyApp then Create application. Then create new application from will appear. Fill all the field and submit it, the application will be create.































Step-4:

Now check all the Default Application Permission, and give the local host link in Authorization Redirect URLs and click on add. Then click on update.




























Step-5:

From the left side menu bar goto JavaScript and set the Valid SDK Domain (your local host URL) and click on add. Then


















Step-6:

Then write the following script in your aspx page.

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

Add control-


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




No comments:

Post a Comment