LinkedIn API - how to query for the total number of connections?
linkedin-api, rest
Solution
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>
Problem
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!