0

I am retrieving connections via LinkedIn's API.

This is a sample of the response. All I want to do is loop through this using PHP, accessing first and last names. Should be simple, but I am stumped. Thanks.

stdClass Object ( [_total] => 420 [values] => Array ( [0] => stdClass Object ( [apiStandardProfileRequest] => stdClass Object ( [headers] => stdClass Object ( [_total] => 1 [values] => Array ( [0] => stdClass Object ( [name] => x-li-auth-token [value] => name:AnUY ) ) ) [url] => http://api.linkedin.com/v1/people/7yw8k_sjqf ) [firstName] => John [headline] => Finance Manager at ABC. [id] => 7yw8k_sjqf [industry] => Insurance [lastName] => Doe [location] => stdClass Object ( [country] => stdClass Object ( [code] => us ) [name] => Greater Atlanta Area ) [pictureUrl] => http://m.c.lnkd.licdn.com/mpr/mprx/0_73E_PMM3nzAIZLG03bHpPRo3qvCwZL_0DhYpPRogIxiFs7jUYPVRGNRGC1mGegyyqdihoC [siteStandardProfileRequest] => stdClass Object ( [url] => http://www.linkedin.com/profile/view?id=2633833&authType=name&authToken=AnUY&trk=api*a189561*s197687* ) ) [1] => stdClass Object ( [apiStandardProfileRequest] => stdClass Object ( [headers] => stdClass Object ( [_total] => 1 [values] => Array ( [0] => stdClass Object ( [name] => x-li-auth-token [value] => name:tpAo ) ) ) [url] => http://api.linkedin.com/v1/people/FW8obZbI8R ) [firstName] => Jeremy [headline] => Owner, BCD [id] => FW8obZbI8R [industry] => Computer Software [lastName] => Doe [location] => stdClass Object ( [country] => stdClass Object ( [code] => us ) [name] => Greater Chicago Area ) [pictureUrl] => http://m.c.lnkd.licdn.com/mpr/mprx/0_Lw2NlImcd1e6LmQpL2mIleOMIcf9LeFpbu4IlexHq-R6V2ryWSpZ0HI6LM7rXeaEYf3Gt69H [siteStandardProfileRequest] => stdClass Object ( [url] => http://www.linkedin.com/profile/view?id=6700159&authType=name&authToken=tpAo&trk=api*a189561*s197687* ) ) [2] => stdClass Object ( [apiStandardProfileRequest] => stdClass Object ( [headers] => stdClass Object ( [_total] => 1 [values] => Array ( [0] => stdClass Object ( [name] => x-li-auth-token [value] => name:eETp ) ) ) [url] => http://api.linkedin.com/v1/people/a7-dvlvc7K ) [firstName] => Jane [headline] => Sr. Consultant System Integration at AT&T [id] => a7-dvlvc7K [industry] => Telecommunications [lastName] => Doe [location] => stdClass Object ( [country] => stdClass Object ( [code] => us ) [name] => Greater New York City Area ) [pictureUrl] => http://m.c.lnkd.licdn.com/mpr/mprx/0_459zxGU8TBpTZjvisicExTgSSvZCsYXisCGExTR-t1ut5V1_N_6JA37p_Z4gJQqIK653RvmW [siteStandardProfileRequest] => stdClass Object ( [url] => http://www.linkedin.com/profile/view?id=119413921&authType=name&authToken=eETp&trk=api*a189561*s197687* ) ) [3] => stdClass Object ( [apiStandardProfileRequest] => stdClass Object ( [headers] => stdClass Object ( [_total] => 1 [values] => Array ( [0] => stdClass Object ( [name] => x-li-auth-token [value] => name:HjUG ) ) ) [url] => http://api.linkedin.com/v1/people/aie8Zpk9Gm ) [firstName] => John [headline] => Financial Information/Market Data Professional [id] => aie8Zpk9Gm [industry] => Financial Services [lastName] => Smith [location] => stdClass Object ( [country] => stdClass Object ( [code] => gb ) [name] => Glasgow, United Kingdom ) [pictureUrl] => http://m.c.lnkd.licdn.com/mpr/mprx/0_N0TLAL3BTlHZCVAbTNTAD03RCjngvsAbCIY-JfOxvg4JldxF9L7MShCp_Avp_ROhKS8LNY [siteStandardProfileRequest] => stdClass Object ( [url] => http://www.linkedin.com/profile/view?id=1562499&authType=name&authToken=HjUG&trk=api*a189561*s197687* ) ) [4] => stdClass Object ( [apiStandardProfileRequest] => stdClass Object ( [headers] => stdClass Object ( [_total] => 1 [values] => Array ( [0] => stdClass Object ( [name] => x-li-auth-token [value] => name:aZIS ) ) ) [url] => http://api.linkedin.com/v1/people/XTGgSuagWI ) [firstName] => Bob [headline] => CEO, Nycomed US at NMO [id] => XTGgSuagWI [industry] => Pharmaceuticals [lastName] => brown [location] => stdClass Object ( [country] => stdClass Object ( [code] => us ) [name] => Greater New York City Area ) [pictureUrl] => http://m.c.lnkd.licdn.com/mpr/mprx/0_UciCehxmKngbM15je_qytdVG-zSbJrcje_92S7a-DlsFcA1m6iCGyXsjl-uwsq3ybXXbrd1L [siteStandardProfileRequest] => stdClass Object ( [url] =>

1 Answer 1

1

What you have as the response is an stdclass which will have all of its properties public.

This is how you iterate it:

$response = $this->getResponseFromLinkedIn();
foreach ($response->values as $value) {
    $firstName = $value->firstName;
    $lastName = $value->lastName;
    // do something with the extracted values!
}
Sign up to request clarification or add additional context in comments.

1 Comment

Fantastic. Works a charm. Thanks :-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.