2
votes

I'm basing my code on the sample PHP code LinkedIn makes available at https://developer.linkedin.com/documents/code-samples.

The differences between their code and mine are few.

The sample code just requests two profile fields:

$user = fetch('GET', '/v1/people/~:(firstName,lastName)');

I wanted a lot more, so I requested all these profile fields as defined at https://developer.linkedin.com/documents/profile-fields:

$user = fetch('GET', '/v1/people/~:(firstName,lastName,headline,industry,specialties,summary,positions,public-profile-url,email-address,interests,publications,languages,skills,certifications,educations,num-recommenders,date-of-birth,honors-awards)');

The request is successful and profile fields are returned and I can print most of them to display. But the fields which are hyphenated, such as public-profile-url don't seem to be returning usable data. I must be doing something wrong, because it can't be a coincidence that all the hyphenated profile field are empty.

After the successful return I tried using print statements to show the results for each field:

print "<br />headline: $user->headline ";
print "<br />industry: $user->industry ";
print "<br /><br />public-profile-url: " . $user->{'public-profile-url'};
print "<br /><br />email-address: " . $user->{'email-address'};

etc.

This works for all the fields that were simple strings. For some I needed to use print_r because they were objects.

But I don't get any data at all for the hyphenated fields.

If I try print_r:

print_r($user->{'public-profile-url'});

the result is blank.

If I try var_dump:

var_dump($user->{'public-profile-url'});

the result is NULL.

This is the same for all the hyphenated profile fields I tried:

public-profile-url email-address num-recommenders date-of-birth honors-awards

It seems to be too much of a coincidence that just the hyphenated profile fields would all be NULL, so I think I must be doing something else wrong.

Any ideas?

Thanks,

doug

3
What do you get when you print_r($user)? - AlexV
The print_r($user) suggestion was an excellent idea! It revealed that LinkedIn was returning public-profile-url as publicProfileUrl, email-address as emailAddress and num-recommenders as numRecommenders. So I can see those values now if I use those property names! LinkedIn does not appear to return anything at all for date-of-birth or honors-awards though. I wonder where they are, though those are less important. Anyway, thanks very much! - Doug Lerner

3 Answers

4
votes

Your method will work, but to be sure... assign the field to a variable first, then use the variable for the reference.

<?php
    $field = 'public-profile-url';

    echo $user->$field; // works

    echo $user->{'public-profile-url'}; // works also
?>

If they are coming back as NULL, then they must be NULL

1
votes

LinkedIn returns always camel case fields, with a lower case first letter, also known as camelBack notation. So you'll have publicProfileUrl, etc. Remember instead, when you require them, to use, for every field, the notation first-name,last-name: compound words separated by comma. Don't use any space before or after the comma.

0
votes

By using print_r($user); you should see to what public-profile-url and others are mapped to.