Integrating LinkedIn Groups in grails application. « Intelligrape Groovy & Grails Blogs

Integrating LinkedIn Groups in grails application.

Posted by

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

This entry was posted on August 24th, 2012 at 8:35 pm and is filed under Grails, Groovy . You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

Leave a Reply