Search code examples
phpdomweb-scrapinglinkedin-api

curl not working for linkedin profile of my connections


I want email id of my friends from linkedin. Till now I got url of my site request url of friends. Which is like https://www.linkedin.com/profile/view?id=xxx&authType=name&authToken=xxx&trk=api*a4152951*s4217191*

(Linkedin API IN.API.Connections("me").result( function(me) { } )

From this url I have to get email address.So I am using curl. Here is my code:

$ch = curl_init("https://www.linkedin.com/profile/view?id=259116153&authType=name&authToken=S9sN&trk=api*a4152951*s4217191*");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true );
$rr = curl_exec($ch);
//curl_close($ch);
echo $rr;

I also tried this but not working (blank page):

$url = $_POST['links'];

$contents = file_get_contents($url);

$dom = new DOMDocument();

@$dom->loadHTML($contents);

$dom->preserveWhiteSpace = false;

$xpath = new DOMXPath($dom);

$hrefs = $xpath->query("//li[@id='contact-field']");

for ($i = 0; $i < $hrefs->length; $i++)
  echo $hrefs->item($i)->nodeValue;

if(!$hrefs) echo 'Not found';
echo $hrefs->nodeValue;

And one more thing if put that url in browser I can see email by click the conatct info button which make display:block (CSS).


Solution

  • Scraping data from LinkedIn is explicitly prohibited by our Terms of Use. The proper way to retrieve data would be via a REST API call.

    Requesting a LinkedIn member's email address requires your application to be requesting a special OAuth permission called: r_emailaddress

    Make sure your application is configured to request that permission, and then use the following REST API call to retrieve a member's email address:

    https://api.linkedin.com/v1/people/id={targetMemberID}:(email-address)
    

    Additional information about making REST API calls can be found here: https://developer.linkedin.com/documents/profile-api