How to use relation-to-viewer in JSAPI

8 posts / 0 new
Last post
Bill Dagou's picture
Joined: 2011-06-08
Jun 18, 2011
How to use relation-to-viewer in JSAPI

I find I will need to use the relation-to-viewer:(related-connections) in my js code, but how can I do that? A simple sample code would be appreciated.Thanks!

Bill Dagou's picture
Joined: 2011-06-08
Jun 20, 2011

I mean, I try to get the people who works in the company, and also the related connections to this person.         IN.API.PeopleSearch()                .fields('firstName', 'lastName', 'headline', 'distance', 'relationToViewer', 'pictureUrl', 'publicProfileUrl')                .params({'company-name': 'COMPANY NAME', 'count': 2, 'sort': 'distance'})                .result(function(result)the relationToViewer only returns the distance. If I'd like to get the related-connections, how should I do?

Kirsten Hunter's picture
Joined: 2011-06-30
Jun 22, 2011

You need to use a Raw API call to get more sub-fields:IN.API.Raw("/people-search:(people:(first-name,last-name,relation-to-viewer:(related-connections)))?keyword=Kirsten").result(function(result) {alert(JSON.stringify(result)) });

Bill Dagou's picture
Joined: 2011-06-08
Jun 23, 2011

Thanks Kirsten.BTW, would you please show me how to use relation-to-viewer:(related-connections)? I triedIN.API.Raw('/people-search:(people:(first-name,last-name,headline,distance,relation-to-viewer:(related-connections),picture-url,public-profile-url))?distance=1')It returns my info and my connections, something like the following


{"people": {
  "values": [
    {
      "headline": "xxxx",
      "publicProfileUrl": "url link",
      "lastName": "Dagou",
      "distance": 0,
      "pictureUrl": "image link",
      "firstName": "Bill",
      "relationToViewer": {}
    },
    {
      "headline": "xxxx",
      "publicProfileUrl": "url link",
      "lastName": "last name",
      "distance": 1,
      "pictureUrl": "image link",
      "firstName": "first name",
      "relationToViewer": {}
    },

    .....  ],   "_count": 10,   "_start": 0,   "_total": 110 }}

I could ignore my info by code for sure, but the relationToViewer field shows empty which is weird I think. Shouldn't it be something like

"relationToViewer": {  "people": {    "values": [      {the connections from my friends},      ....    ]  }}
Kirsten Hunter's picture
Joined: 2011-06-30
Jun 23, 2011

That's odd.  Can you take a look at this example page and see what you get in the alert?http://developer.linkedinlabs.com/tutorials/testing.html

Bill Dagou's picture
Joined: 2011-06-08
Jun 25, 2011

{"numResults":26298,"people":{"values":[{"headline":"President of Princess Promotion Enterprise.","id":"3uqKd9p572","lastName":"Private","firstName":""}],"_count":1,"_start":0,"_total":110}}Here is the alert.

Nichehire Jobs's picture
Joined: 2011-11-13
Feb 22, 2012

i just wanted to get the connections on company in my network....the code iam using is...

IN.API.PeopleSearch()
.fields('id', 'firstName', 'lastName', 'distance', 'positions:(title)',
'public-profile-url', 'picture-url', 'relation-to-viewer:(related-connections)')
.params({
'company-name': 'Apple',
'current-company': true,

})
.result(displayMyConnections);

in this i wanted to use FACTS firstdegree and second degree...
can some body helpme out with example....

Steven Citron-Pousty's picture
Joined: 2011-08-02
Feb 23, 2012

Greetings Tharakki:
I am not sure what you are trying to do? Can you please try to explain what you are trying to do some more...
Thanks
Steve