Last active
October 3, 2019 05:08
-
-
Save Abdurraheem/98e72baeb4a62fcfd71fd6d90a57805f to your computer and use it in GitHub Desktop.
Nodejs Post on LinkedIn using REST API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @param Function : Post on LinkedIn | |
* @param Send Json data of Text/Photos with POST | |
* @Date: 15 Feb, 2018 | |
*/ | |
function linkedInPost(req, res) { | |
var access_token = req.body.auth.access_token; | |
var jsonBody = { | |
"comment": jsonData.comment, | |
"visibility": { | |
"code": 'anyone' | |
}, | |
"content" :'submitted-image-url' | |
} | |
var url = 'https://api.linkedin.com/v1/people/~/shares?format=json'; | |
var options = { | |
method: 'POST', | |
url: url, | |
headers: { | |
'Content-Type': 'application/json', | |
'x-li-format': 'json', | |
Authorization: 'Bearer ' + access_token | |
}, | |
body: JSON.stringify(jsonBody) | |
}; | |
request(options, function (err, response) { | |
if(err){ | |
res.send(err); | |
} | |
else if (JSON.parse(response.body).status) { | |
res.send({data: JSON.parse(response.body).message}); | |
} else { | |
res.send('Your File is suceessfully Posted'); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment