Question

I have to login and post content in linkedin using javascript. Using below code i have login successfully and when i have posted i got below error in firebug .

NetworkError: 403 Forbidden - https://api.linkedin.com/v1/people/~/mailbox

I need to post content in wall.

what is the issue in below code

<script type="text/javascript" src="http://platform.linkedin.com/in.js"> 
    api_key: xxxxxxx
    onLoad: onLinkedInAuth
    scope: r_network w_messages
    authorize: true
     </script>

     <script type="text/javascript">

     function onLinkedInLoad() {

         IN.Event.on(IN, "auth", onLinkedInAuth);
     } 

     function onLinkedInAuth() {

        var div = document.getElementById("sendMessageForm");

         div.innerHTML = '<h2>Send a Message To Yourself</h2>';
         div.innerHTML += '<form action="javascript:SendMessage();">' +
                     '<input id="message" size="30" value="You are awesome!" type="text">' +
                      '<input type="submit" value="Send Message!" /></form>';
     }

     function SendMessage(keywords) {


         var message = document.getElementById('message').value; 
       var BODY = {
            "recipients": {
               "values": [{
                "person": {
                   "_path": "/people/~",
                }
              }]
             },
          "subject": "JSON POST from JSAPI",
         "body": message
        }

         IN.API.Raw("/people/~/mailbox")
               .method("POST")
               .body(JSON.stringify(BODY)) 
               .result(displayMessageSent)
               .error(function error(e) { alert ("No dice") });
     }

     function displayMessageSent() {
         var div = document.getElementById("sendMessageResult");
          div.innerHTML += "Yay!";
     }

     </script>
     </head>
     <body>
     <script type="IN/Login"></script>
     <div id="sendMessageForm"></div>
     <div id="sendMessageResult"></div>
Was it helpful?

Solution

Using below javascript code I posted linkedin

IN.API.Raw("/people/~/current-status") // Update (PUT) the status
  .method("PUT")
  .body(JSON.stringify("Test Message"))
  .result( function(result) { document.getElementById("statusDiv").innerHTML = "Status   updated"; } )
  .error(  function(error)  { /* do nothing */ } );
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top