Skip to content

Instantly share code, notes, and snippets.

@vmcilwain
Created October 2, 2019 15:01
Show Gist options
  • Save vmcilwain/5a043013f69eb94a327e7a3482f433d4 to your computer and use it in GitHub Desktop.
Save vmcilwain/5a043013f69eb94a327e7a3482f433d4 to your computer and use it in GitHub Desktop.
Post/Share an article to LinkedIn via HTTParty
# Post/Share article
# via HTTParty
# the needed headers
headers = {
"Content-Type" => "application/json",
"x-li-format" => "json",
"X-Restli-Protocol-Version" => "2.0.0",
"Authorization" => "Bearer Access-Token"
}
# the post to share
body = {
author: "urn:li:person:abc-123",
lifecycleState: "PUBLISHED",
specificContent: {
"com.linkedin.ugc.ShareContent" => {
shareCommentary: {
text: "A"
},
shareMediaCategory: "ARTICLE",
media: [
{
status: "READY",
description: {
text: "B"
},
originalUrl: "https://www.linkedin.com/",
title: {
text: "C"
}
}
]
}
},
visibility: {
"com.linkedin.ugc.MemberNetworkVisibility" => "CONNECTIONS"
}
}
# initiate the post
HTTParty.post('https://api.linkedin.com/v2/ugcPosts', headers: headers, body: body.to_json)
# the returned id on success
=> {"id"=>"urn:li:share:65851610128513xxxx"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment