How to share post to linkedin
Asked Answered
H

1

6

My task is to share a post to linked in from a page. I have gone through linked in documentation, but I couldn't understand what to do. I have googled for days and I didn't get a clear idea.

Can anyone clearly explain about how to share to linkedin. I dont want to share a whole page but only a particular post.

Here is the code I got from the net, but I have no idea what is happening in this code.

<html>
<head>
<script type="text/javascript" src="//platform.linkedin.com/in.js">
  api_key: xxxxxxxxx
  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() {
            // Build the JSON payload containing the content to be shared
      var payload = {
            Content-Type: application/json
            x-li-format: json
            "comment": "Check out developer.linkedin.com!",
            "content": {
                "title": "LinkedIn Developers Resources",
                "description": "Leverage LinkedIn's APIs to maximize engagement",
                "submitted-url": "https://developer.linkedin.com",  
                "submitted-image-url": "https://example.com/logo.png"
            },
           "visibility": {
               "code": "anyone"
           }  
      };

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

</script>
</head>
<body>
    <script src="//platform.linkedin.com/in.js" type="text/javascript"> lang: en_US</script>
    <script type="IN/Share"></script>
</body>
</html>

Do I need any other files along with the codes?

I am working in codeigniter.

Please help.

Thanks in advance.

Hying answered 11/1, 2016 at 6:3 Comment(1)
have u managed to make it work ? I have the same issue and I'm using codeigniter too..Thoth
C
1

I read your javascript code, it's doing what you want actually but i think you should do this thing in php or nodejs like backend languages.

To do this thing and also more you need to use Linked in's REST API.
All REST API's have same architecture, first you need to authenticate your account, after then send requests and get responses (with same session) and do what you want.

Edit: I've found exactly what you want in here

Colcannon answered 16/3, 2017 at 21:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.