Integrating LinkedIn Groups in grails application.

24 / Aug / 2012 by Vishal Sahu 1 comments

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 :-

[java]
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
}
[/java]

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:

[java]
http://api.linkedin.com/v1/groups/${linkedInGroupId}/posts?format=json&count=30&start=30
[/java]

This will retrieve latest 30 group discussions in JSON format.


This worked for me. Hope this helps…:)


Useful Links:

https://developer.linkedin.com/rest


Cheers..!!!
Vishal Sahu
vishal@intelligrape.com

FOUND THIS USEFUL? SHARE IT

comments (1 “Integrating LinkedIn Groups in grails application.”)

Leave a Reply

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