As a sequel to my earlier post, Programmatically Posting to LinkedIn Groups via LinkedIn REST API and using Scribe-Java OAuth Library, in this post I will demonstrate how you can Flag a Post or a Discussion in a LinkedIn Group as a Promotion or a Job using Scribe and Java.
Consider the output of our example program in my previous post:
Notice the following header and its value:
Location = http://api.linkedin.com/v1/posts/g-5046253-S-259167773
This URL contains the post id of the published post and it is the very last part of the URL “g-5046253-S-259167773”.
So, what we will do now is the extend the same program/example and will try to extract the “Location” header value and then extract the “post-id” from that value:
String preUrl = "http://api.linkedin.com/v1/posts/";
String url = response.getHeader("Location").substring(preUrl.length());
url = preUrl + url + "/category/code";
Once you have the target URL, you can now proceed with the HTTP PUT request, using the url as a LinkedIn REST API end point.
OAuthRequest request = new OAuthRequest(Verb.PUT, url);
Now, if you want to Flag your Post or Discussion as a Promotion, you should add following XML stanza as the pay load to this request:
OR, if you want to Flag your Post or Discussion as a Job, you should add following XML stanza as the pay load to this request:
And, finally send the request to LinkedIn REST API server:
response = request.send();
When you run this updated program, you will see an output similar to the following on your console:
The Code 204 is fine, in our case as it complains about “No Content”. Your Post or Discussion on a LinkedIn Group has been Flagged as a Promotion or a Job.