Hi,
In one of my recent Grails application, i needed to integrate LinkedIn groups with the application.
In my previous post, we discussed about Integrating LinkedIn API in any grails application. To add a LinkedIn Group, we first need to authorize the LinkedIn account which has either created that group or is the member/admin of the group with the rights to publish new post in that group.
After obtaining linkedIn_token and linkedIn_secret as mentioned in this blog, we need to make another call to retrieve all the Linked Groups for that account.
Code to retrieve all the LinkedIn Groups is as :-
String apiKey = API_KEY obtained from registered LinkedIn Application
String apiSecret = API_SECRET obtained from registered LinkedIn Application
Map linkedInGroupMap = [:]
LinkedInAccessToken accessToken = new LinkedInAccessToken(linkedIn_token, linkedIn_secret)
LinkedInApiClientFactory factory = LinkedInApiClientFactory.newInstance(apiKey, apiSecret)
LinkedInApiClient linkedInClient = factory.createLinkedInApiClient(accessToken)
GroupMemberships groupMemberships = linkedInClient.getGroupMemberships()
groupMemberships.groupMembershipList.each {GroupMembership groupMembership ->
linkedInGroupMap[groupMembership.group.id] = groupMembership.group.name
}
So, the resulting map will contains the key, value pairs of linkedIn groups ID and Name.
Now we can store these Group IDs for making API calls to :-
#. Retrieve group’s profile details.
#. Read, Create, Like, Comment group posts
Example API call to retieve group’s discussion wall posts:
http://api.linkedin.com/v1/groups/${linkedInGroupId}/posts?format=json&count=30&start=30
This will retrieve latest 30 group discussions in JSON format.
This worked for me. Hope this helps…:)
Useful Links:
https://developer.linkedin.com/documents/groups-api
https://developer.linkedin.com/documents/groups-fields
https://developer.linkedin.com/rest
Cheers..!!!
Vishal Sahu
vishal@intelligrape.com
http://www.intelligrape.com


Reading comments of LinkedIn wall post
Hi,
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() .provider(LinkedInApi.class) .apiKey(consumerKey) .apiSecret(consumerSecret) .debug() .build(); String url = "http://api.linkedin.com/v1/people/~/network/updates/key=${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.
Cheers..!!!
Vishal Sahu
vishal@intelligrape.com
www.linkedin.com/in/vishalsahu