【问题标题】:Cannot fetch LinkedIn shared connections无法获取 LinkedIn 共享连接
【发布时间】:2013-09-12 19:11:49
【问题描述】:

我目前正在开发一个 Grails 应用程序(使用类似于 Java 的 Groovy),用户可以在其中查看其他用户的个人资料。在用户的个人资料页面上,我需要显示该用户与查看者的 LinkedIn 个人资料之间共享的 LinkedIn 连接。 对于 LinkedIn 集成,我目前正在使用 linkedin-j.jar

使用我从 API 文档和 Google 搜索中猜到的所有信息,我编写了以下代码,但未能成功获取共享连接。

任何帮助将不胜感激。

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

(这里当前用户是查看者,目标用户是正在查看其个人资料的用户。)

运行此代码后,我得到以下结果:

resultProfile.relationToViewer.relatedConnections: NULL

resultProfile.relationToViewer.distance: 2

但这并不像预期的那样,两个用户的 LinkedIn 个人资料都有一个共享连接

【问题讨论】:

  • 所以distance 是对的,但relatedConnections 是错的?
  • 是的蒂姆,你是对的。

标签: java groovy linkedin linkedin-j


【解决方案1】:

我能够解决这个问题。

我遗漏的地方是:

  1. 我用来检索数据的 API 密钥和机密的 LinkedIn 应用程序被配置为只请求 BASIC_PROFILE 权限(这是因为 LinkedIN recently introduced some changes in their API Permissions)。访问连接信息也需要网络权限。

  2. 在代码中,我应该使用 ProfileField.RELATION_TO_VIEWER_RELATED_CONNECTIONS 代替 ProfileField.RELATION_TO_VIEWER

以下是对我有用的最后一段代码:

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_RELATED_CONNECTIONS] as Set)

List<Person> commonConnections= resultProfile.relationToViewer.relatedConnections.personList

【讨论】:

    猜你喜欢
    • 2016-05-08
    • 1970-01-01
    • 2013-09-16
    • 1970-01-01
    • 1970-01-01
    • 2015-04-24
    • 2014-07-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多