LinkedIn API - how to query for the total number of connections?

谁都会走 提交于 2019-12-20 02:40:09

问题


I am trying to query for the total number of connections like this:

/people/id=QM86-RIKjb:(connections total)

and using the API example here: https://developer.linkedin.com/documents/profile-api

in the xml example towards the bottom the show this field: <connections total="" >

I am trying to query for it, but I get an exception that I have a bad URI:

URI::InvalidURIError: bad URI(is not URI?): /v1/people/id=QM86-RIKjb:(connections total)

What am I doing incorrectly? Is there a correct way to query for such parameters?

Thanks!


回答1:


To get the connection count from the Profile API, you can ask the API directly:

http://api.linkedin.com/v1/people/id=nbqwYraDfd:(num-connections,num-connections-capped)

Which will return (depending on the connection count):

<?xml version="1.0" encoding="UTF-8"?>
<person>
  <num-connections>500</num-connections>
  <num-connections-capped>true</num-connections-capped>
</person>

Keep in mind that there are restrictions on the fields available to the viewing user - check the Profile Fields document for details. For instance, it is not possible to get 'connections of connections' - if, in your example above, nbqwYraDfd represents the current viewing user, you can use:

http://api.linkedin.com/v1/people/id=nbqwYraDfd:(connections)

Which will return:

<?xml version="1.0" encoding="UTF-8"?>
<person>
  <connections total="XXX" count="YYY" start="0">
    <person>
    ...
    </person>
  </connections>
</person>

And then check the value of total by traversing the XML (language dependant).

However, if nbqwYraDfd is a connection of the current user, or a non-connection, you will get a 403 response:

<?xml version="1.0" encoding="UTF-8"?>
<error>
  <status>403</status>
  <timestamp>1337954306491</timestamp>
  <request-id>25P44ZN249</request-id>
  <error-code>0</error-code>
  <message>Access to other member's connections denied</message>
</error>



回答2:


You cannot do this ( you cannot get an attribute of a particular tag)

Do this,

http://api.linkedin.com/v1/people/id=nbqwYraDfd:(connections)

Get the response returned and parse the XML returned in your programming language and read the attribute total of connections tag.

If you are interested in getting total count only, I would suggest this query to filter the response returned,

http://api.linkedin.com/v1/people/id=nbqwYraDfd:(connections:())

Which programming language are you using, may be I can help in parsing the XML returned.



来源:https://stackoverflow.com/questions/10745255/linkedin-api-how-to-query-for-the-total-number-of-connections

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!