Reading comments of LinkedIn wall post

26 / Sep / 2012 by Vishal Sahu 0 comments


In one of my grails project, i needed to show the comments on any wall post of linkedin through API. I used the Java wrapper to connect any linkedIn account with the grails application which can be seen here. But somehow this library was not working when we need to fetch comments from any wall post and display them in our UI.

I searched a lot about it but couldn’t find anything appropriate, then i decided to use the linkedIn API directly for retrieving the data. To make GET calls , i used the Scribe java library which can be downloaded from here.

To make API calls on linkedIn, we need to have an authenticated account’s access_token and access_secret, which can be obtained by connecting a linkedIn account with the application as mentioned in this post.

Code to fetch comments on LinkedIn Wall post :-

String consumerKey = CONSUMER_KEY // key obtained by linkedIn app
String consumerSecret = CONSUMER_SECRET // secret obtained from linkedIn app
String accessToken = ‘assess_token’
String accessSecret = ‘access_secret’
String postId = POST_ID // id of the wall post

OAuthService service = new ServiceBuilder()
String url = "${postId}/update-comments?format=json";

OAuthRequest request = new OAuthRequest(Verb.GET, url);
org.scribe.model.Token accessToken = new org.scribe.model.Token(accessToken,accessSecret)
service.signRequest(accessToken, request);
Response response = request.send();
String jsonResponse = response.getBody()
def updates = JSON.parse(jsonResponse) // contains comments data in JSON format

updates.values.each {def commentData ->
println "Comment : ${commentData.comment}"
println "Creator: ${commentData.person.firstName}"


This code will fetch the comments from any linkedin wall post. It worked in my case.

Hope it helps.


Leave a Reply

Your email address will not be published. Required fields are marked *