I am currently working on a Grails application (using Groovy which is similar to Java), where a user can view the profile of other users. On user's profile page, I need to show the LinkedIn connections shared between that user and the viewer's LinkedIn profiles. For LinkedIn integration, I am currently using linkedin-j.jar
Using all that I could guess from the API documentation and Google search, I wrote the following code, which was unsuccessful to fetch shared connections.
Any help will be appreciated.
LinkedInAccessToken targetUserLiAccessToken = new LinkedInAccessToken(targetUserOauthToken, targetUserOauthSecret)
LinkedInApiClient targetUserLiApiClient= linkedInApiClientFactory.createLinkedInApiClient(targetUserLiAccessToken)
Person targetUserLiProrfile=targetUserLiApiClient.getProfileForCurrentUser([ProfileField.ID] as Set)
LinkedInAccessToken currentUserLiAccessToken = new LinkedInAccessToken(currUserOauthToken, currUserOauthSecret)
LinkedInApiClient currentUserLiApiClient= linkedInApiClientFactory.createLinkedInApiClient(currentUserLiAccessToken)
Person resultProfile = currentUserLiApiClient.getProfileById(targetUserProfile.id, [ProfileField.ID, ProfileField.RELATION_TO_VIEWER] as Set)
List<Person> commonConnections= resultProfile.relationToViewer.relatedConnections.personList
(Here the current User is viewer and target User is the one whose profile is being viewed.)
Upon running this code, I am getting the following results:
resultProfile.relationToViewer.relatedConnections: NULL
resultProfile.relationToViewer.distance: 2
But this is not as expected, the LinkedIn Profiles of both the users have one shared Connection