Integrate linkedin api in your site

linkedin-logoNow a days most popular host sites provide api so that we integrate in our site to create mash-up application. Linkedin recently published their own apis. So now we can integrate linkedin apis in our site. So why we should integrate linkedin api:

  1. Users can bring linkedin profile and network in your site
  2. There are 52 millions users in linkedin so you can engage them in your site
  3. You may create authentication through linkedin api so that user don’t need to register in your site
  4. You can search profile, connection
  5. Users can also update their status from your site using linkedin apis
  6. And many more…

In this tutorial I’ll show how could you integrate linkedin api in your site, search a company name and get your profile info.

Before proceeding:

Demo AppDownload Code

Look at the LinkedIn APIs Terms of Use

1.visit https://www.linkedin.com/secure/developer and click Add New Application.

Now fill the form. You have to must fill * Indicates.

Integration Url would be your project url. Here I filled http://thinkdiff.net/demo/linkedin

oAuth Redirect Url would be the web page url. In my case I provides http://thinkdiff.net/demo/linkedin/demo.php

Now click Add Application. Then you’ll get Api Key and Secret Key for your application.

Linkedin also used oAuth library, so if you don’t understand what is oAuth you can read my earlier article http://thinkdiff.net/php/develop-auto-post-publishing-twitter-app/

Now look at the project files

Now look at auth.php codes

<?php
    session_start();

    $config['base_url']             =   'http://thinkdiff.net/demo/linkedin/auth.php';
    $config['callback_url']         =   'http://thinkdiff.net/demo/linkedin/demo.php';
    $config['linkedin_access']      =   'xxxxxxxxxxxxxxYour_API_KEYxxxxxxxxxxxx';
    $config['linkedin_secret']      =   'xxxxxxxxxxxxxxYour_Secret_Keyxxxxxxxxx';

    include_once "linkedin.php";

    # First step is to initialize with your consumer key and secret. We'll use an out-of-band oauth_callback
    $linkedin = new LinkedIn($config['linkedin_access'], $config['linkedin_secret'], $config['callback_url'] );
    //$linkedin->debug = true;

    # Now we retrieve a request token. It will be set as $linkedin->request_token
    $linkedin->getRequestToken();
    $_SESSION['requestToken'] = serialize($linkedin->request_token);

    # With a request token in hand, we can generate an authorization URL, which we'll direct the user to
    //echo "Authorization URL: " . $linkedin->generateAuthorizeUrl() . "\n\n";
    header("Location: " . $linkedin->generateAuthorizeUrl());
?>

Now look at the demo.php codes

<?php
    session_start();

    $config['base_url']             =   'http://thinkdiff.net/demo/linkedin/auth.php';
    $config['callback_url']         =   'http://thinkdiff.net/demo/linkedin/demo.php';
    $config['linkedin_access']      =   'xxxxxxxxxxxxxxYour_API_KEYxxxxxxxxxxxx';
    $config['linkedin_secret']      =   'xxxxxxxxxxxxxxYour_Secret_Keyxxxxxxxxx';

    include_once "linkedin.php";

    # First step is to initialize with your consumer key and secret. We'll use an out-of-band oauth_callback
    $linkedin = new LinkedIn($config['linkedin_access'], $config['linkedin_secret'], $config['callback_url'] );
    //$linkedin->debug = true;

   if (isset($_REQUEST['oauth_verifier'])){
        $_SESSION['oauth_verifier']     = $_REQUEST['oauth_verifier'];

        $linkedin->request_token    =   unserialize($_SESSION['requestToken']);
        $linkedin->oauth_verifier   =   $_SESSION['oauth_verifier'];
        $linkedin->getAccessToken($_REQUEST['oauth_verifier']);

        $_SESSION['oauth_access_token'] = serialize($linkedin->access_token);
        header("Location: " . $config['callback_url']);
        exit;
   }
   else{
        $linkedin->request_token    =   unserialize($_SESSION['requestToken']);
        $linkedin->oauth_verifier   =   $_SESSION['oauth_verifier'];
        $linkedin->access_token     =   unserialize($_SESSION['oauth_access_token']);
   }

    # You now have a $linkedin->access_token and can make calls on behalf of the current member
    $xml_response = $linkedin->getProfile("~:(id,first-name,last-name,headline,picture-url)");

    echo '<pre>';
    echo 'My Profile Info';
    echo $xml_response;
    echo '<br />';
    echo '</pre>';

    $search_response = $linkedin->search("?company-name=facebook&count=10");

    //echo $search_response;
    $xml = simplexml_load_string($search_response);

    echo '<pre>';
    echo 'Look people who worked in facebook';
    print_r($xml);
    echo '</pre>';
?>

Now visit your site’s url in my case http://thinkdiff.net/demo/linkedin/auth.php

After login in linkedin and providing access it will redirect to http://thinkdiff.net/demo/linkedin/demo.php and you’ll see your linkedin profile information and some peoples information who worked  in facebook. If you want to search other company just modify this line

$search_response = $linkedin->search("?company=your_desire_company&count=10");

You can also search name, title and many more. To see the complete list of parameters check http://developer.linkedin.com/docs/DOC-1005

To get more information about linkedin api please visit http://developer.linkedin.com/community/apis

You can also update the linkedin.php library and add new method for your purpose. For example look at the search method of this file

function search($parameters) {
    $search_url = $this->base_url . "/v1/people-search:(people:(id,first-name,last-name,picture-url,site-standard-profile-request,headline),num-results)" . $parameters;
    //$search_url = $this->base_url . "/v1/people-search?keywords=facebook";

    echo "Performing search for: " . $parameters . "<br />";
    echo "Search URL: $search_url <br />";
    $request = OAuthRequest::from_consumer_and_token($this->consumer, $this->access_token, "GET", $search_url);
    $request->sign_request($this->signature_method, $this->consumer, $this->access_token);
    $auth_header = $request->to_header("https://api.linkedin.com");
    if ($debug) {
      echo $request->get_signature_base_string() . "\n";
      echo $auth_header . "\n";
    }
    $response = $this->httpRequest($search_url, $auth_header, "GET");
    return $response;
  }

So the function’s code is not too difficult to understand, right? So if you want to add invitation api http://developer.linkedin.com/docs/DOC-1012 in your project then create a new function like function invitation(){} where you’ll implement the invitation api from linkedin by copying the above code and modifying  some lines.

And don’t forget to know about some limits by linkedin, regarding api calls. Visit http://developer.linkedin.com/docs/DOC-1112 to know details.

I hope you understand about the basic usage of linkedin apis and you can now integrate in your project easily.

About mahmud ahsan

I'm a Technology Enthusiast & ZCE. My primary fields of work are web & iPhone application development. I'm founder of iThinkdiff.net - a small iOS application development studio and Thinkdiff.net - a familiar technical blog. My passion is programming, software & game development. To know more about me visit my portfolio page.

, , , ,

130 Responses to Integrate linkedin api in your site

  1. ranacse05 March 16, 2010 at 8:08 pm #

    Nice post , thanks for share :)

  2. hasin March 18, 2010 at 3:10 am #

    definitely a very good article. i like as you described every steps nicely :)

  3. Alvin March 18, 2010 at 3:58 pm #

    Very detailed article. However, I can’t seem to find the linkedin.php file in http://oauth.googlecode.com/svn/code/php/ Any help is appreciated. Thanks.

  4. mahmud ahsan March 18, 2010 at 4:50 pm #

    @Alvin, I updated the link actually download the linkedin.php and oauth.php from here

    http://developer.linkedin.com/servlet/JiveServlet/download/3005-1178/LinkedInOAuth-PHP-WithSearch.zip;jsessionid=8AD7DC6FC927780812298C29BF7F2217.node0

  5. Iris March 19, 2010 at 2:06 am #

    Hi,

    I want to know how linkedin can update the status message in itself and twitter at the same time. Where can I find the source code?

  6. mahmud ahsan March 19, 2010 at 3:02 am #

    @Iris, you’ve to develop your own solution. You can integrate this solution with http://thinkdiff.net/php/develop-auto-post-publishing-twitter-app/ twitter solution so that you can update twitter status and linkedin status at the same time.

  7. Iris March 19, 2010 at 12:38 pm #

    @ Mahmud: Thanks!

    I have already gone through that but my question is what else is there apart from the four steps in that. I mean that it self is a solution right?

  8. mahmud ahsan March 19, 2010 at 12:49 pm #

    @Iris, you’ve to modify the codes so that is serves your purpose. Simply the logic is, you need a admin panel where you’ll first authenticate twitter and linkedin and you need a text field where you’ll put your status. After submit the status will update in linkedin and twitter. So you’ve to code what will happen after submission. I’ll keep in mind about your problem and if I make time, I’ll write a post regarding it. So tune my site. :)

  9. Alvin March 19, 2010 at 12:59 pm #

    @mahmud ahsan, thanks a lot for the link. However, right now I have an error at the LinkedIn authorization page which says “We were unable to find the authorization token”. Upon googling, one possible problem could be because my system clock is out of sync with LinkedIn’s. Any clue on how do I sync my system clock?

  10. mahmud ahsan March 19, 2010 at 1:14 pm #

    @Alvin, this is very weird. And I’m really not sure why this happened. One thing you can try with different browser or different Os. Sometimes the bug may happen on linkedin, I’m not sure!!!

  11. Alvin March 19, 2010 at 2:33 pm #

    @mahmud ahsan, I realized that when I reach the authorization step, my application does not have an authorization URL generated. Just wondering whether there’s anything I need to edit besides the base_url, callback_url, API key and secret key?

    If I’m testing on localhost, is it an issue?

  12. mahmud ahsan March 19, 2010 at 8:47 pm #

    @Alvin, i’m not sure is the problem happened for localhost or not as I directly tested that code on server.

  13. Alvin March 21, 2010 at 8:17 pm #

    @mahmud ahsan, never mind. I’ll try to figure out how to solve it. Thanks for the help anyway.

  14. Alvin March 22, 2010 at 8:50 pm #

    @mahmud ahsan, I’ve managed to get the linkedin api working with Zend Oauth framework. However, I would still like to make use of your codes as it’s simpler to understand (and hence easier to make future modifications). I did some tests on my codes and made the following observations:

    I realized that the problem lies in the request token step. I printed out the $response object in the getRequestToken() function in linkedin.php and it’s empty.

    It seems that the $data object in the httpRequest() function in linkedin.php is empty as well. As such, I would like to check with you whether the parameter values that I’m passing in is correct:

    $url = https://api.linkedin.com/uas/oauth/requestToken?oauth_callback=http%3A%2F%2Flocalhost%2Flinkedin2%2Fdemo.php&oauth_consumer_key=LrH1Ck7-bNVGX57WstY_HxnmsPbIN1a4OIwi-LjUnAsHKJJaks2DU6ahIa5kb5DJ&oauth_nonce=698b4ab5efafeadd382884b26fd858c4&oauth_signature=%2BRV59Bm4pZfpGP9mkWC5BCiy56k%3D&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1269265649&oauth_version=1.0
    $auth_header = Array
    $method = GET

    Thank you for your help.

  15. mahmud ahsan March 22, 2010 at 9:26 pm #

    @Alvin, I didn’t pass any parameter by myself, and couldn’t understand what the problem you’re facing. Did you run successfully my code yourself, my codes working nicely here http://thinkdiff.net/demo/linkedin/auth.php

  16. Alvin March 22, 2010 at 9:35 pm #

    @mahmud ahsan, I’m able to run your auth.php perfectly. The problem is that when I reach the authorization page, I am unable to retrieve a request token so the authorization url has no value for oauth_token.

  17. mahmud ahsan March 22, 2010 at 10:12 pm #

    @Alvin, In the application setting, did you provide the oAuth Redirect url correctly ? And also check if session is working correctly or not. some of my friends, run my codes successfully without any problem. So its really confusing why this problem occurs in your side. Are you running the code in localhost or in any server?

    • Allabakash August 19, 2011 at 5:24 pm #

      i have problem in sessions

      your software is awesome, but my session getting reset once after Header function,

      its very much cool at auth.php–>i got a linkedin login page,it worked fine and good, its again coming back to my callback page(demo.php)..here it shows 404,
      its due to the session variable getting reseted ,,,

      please suggest me ,what are the precautions you took in php.ini file, and please let me know, if i have missed anything

      Regards/Jazakalla
      AB

  18. Alvin March 22, 2010 at 11:01 pm #

    @mahmud ahsan, my callback url should be correct. In any case, here’s my settings

    $config['base_url'] = ‘http://localhost/linkedin2/auth.php’;
    $config['callback_url'] = ‘http://localhost/linkedin2/demo.php’;

    Besides setting these 2 config parameters and the API key and secret, is there any other changes I need to make? I’ve not made any changes in OAuth.php and linkedin.php; is there anything I need to change in these 2 files?

    I’m sure that your codes are fine, because I can run your example perfectly so I think the problem should lie with my configurations, which I’m trying to figure out where the problem lies.

    I’m running the code on localhost but that shouldn’t be a problem since I can run the codes successfully on localhost using the Zend OAuth framework.

    If I still can’t figure out how to solve this then I guess I’ll stick to using the Zend OAuth framework then. Anyway, thanks for your help so far.

    • Viren August 13, 2010 at 1:14 pm #

      Hi Alvin,

      I am also facing the same problem as you did “We were unable to find the authorization token”.
      How did you solve the problem by using Zend frameowrk. What exaclty you mean when you say you used Zend framework. Is it Server? or anything else or any change in the code..

      Thanks,
      Viren

  19. mahmud ahsan March 22, 2010 at 11:05 pm #

    @Alvin, Please run this code in server, not in your localhost. I think you’ll face no problem. There is no more changes on other files those you mentioned. May be zend oAuth library works differently than my example.

  20. Alvin March 23, 2010 at 9:01 pm #

    @mahmud ahsan, I guess I’ll stick to my working Zend OAuth framework then since it’s the only one I can get to work. Thanks for the help anyway. Really appreciate it.

  21. Tony Petrov March 25, 2010 at 9:51 pm #

    Hello,

    if I store ‘requestToken’, ‘oauth_verifier’ and ‘oauth_access_token’ in DB is possible to use it after 1,2,10 days?

    regards,

  22. mahmud ahsan March 26, 2010 at 12:00 am #

    @Tony, if user approve the permission as Until Revoked then you can use it for infinite time. But if user approve for one day or one week then you’ve no choice.

  23. amores April 12, 2010 at 8:55 pm #

    Hi.
    Maybe I didn’t understood something, but each time after login, when I want to get profile (with specified fields, or only with ‘~’) I get the error:

      404
      1271080357982
      0000
      Could not find person based on: ~
    

    I can’t investigate what is wrong, can’t make it work.
    My header is:

    realm="",oauth_version="1.0",oauth_nonce="",oauth_timestamp="1271080357",
    oauth_consumer_key="[key]",oauth_signature_method="HMAC-SHA1",oauth_signature="
    

    Is there anything what I should check?

    • swapnil February 8, 2011 at 4:14 pm #

      Hi,

      I am also going through the same problem of Could not find person based on: ~

  24. mahmud ahsan April 12, 2010 at 10:50 pm #

    @Amores, I think the problem is something related authentication. Please visit this link http://thinkdiff.net/demo/fblinkedtwit/index.php and check if linkedin works for you or not. And the code for this project is open source checkout the article: http://thinkdiff.net/facebook/open-source-facebook-twitter-linkedin-status-update-application/

  25. itsmeok April 13, 2010 at 5:12 am #

    I tried running the php codes, but it does not result/output anything. I tried ‘debugging’ the auth.php file and when i

    ‘echo “Authorization URL: ” . $linkedin-> generateAuthorizeUrl() . “\n\n”; ‘

    i get the following:

    Authorization URL: https://api.linkedin.com/uas/oauth/authorize?oauth_token=

    I have a feeling that $linkedin is empty, ie. the ‘ new LinkedIn() ‘ command is not generating anything. Any reasons as to why this might be happening?

    • Allabakash August 16, 2011 at 1:05 pm #

      That is due to TimeStamp_refused error in OAuth.php,
      you will find more in below blog http://developer.linkedin.com/thread/1202,

      you have to sync with NTP timestamp to get this work,

      even after generating oauthToken, am getting 404 in demo.php,
      please suggest,thanks in advance

  26. mahmud ahsan April 13, 2010 at 5:16 am #

    @itsmeok, same answer for you. Please check this article http://thinkdiff.net/facebook/open-source-facebook-twitter-linkedin-status-update-application/ and check if linkedin status update works for you or not. If it works for you then please checkout the code of that project.

  27. itsmeok April 13, 2010 at 6:11 am #

    Thanks for the quick reply, mahmud!

    I tried the link you gave me, the linkedin access was working on your link. However, when i checkedout the code and ran it on localhost, and click on ‘Give LinkedIn access’, it opens a blank page.

    Have you faced this before? Am i doing something wrong?

  28. mahmud ahsan April 13, 2010 at 12:19 pm #

    @itsmeok, i think this code will not work in localhost, but I’m not sure. Normally I tested this code directly on server.
    thanks.

  29. amores April 14, 2010 at 5:36 pm #

    I wan’t to create profile in my page basing on my profile from linkedIn but I can’t get my email address. Is there any way to do pass it via XML? If not – maybe I could save it in session somehow?

  30. mahmud ahsan April 15, 2010 at 1:02 am #

    @amores, I don’t find email retrieving system in their api documentation http://developer.linkedin.com/docs/DOC-1002
    You can save email to session as your own way.

  31. Jarrod April 22, 2010 at 6:41 am #

    Just to let people know if you use the above method of getting the linkedin.php file, that the setStatus function is not working correctly.

    It should be:

    function setStatus($status) {
        $status_url = $this->base_url . "/v1/people/~/current-status";
        echo "Setting status...\n";
        $xml = "" . htmlspecialchars($status, ENT_NOQUOTES, "UTF-8") . "";
        echo $xml . "\n";
        $request = OAuthRequest::from_consumer_and_token($this->consumer, $this->access_token, "PUT", $status_url);
        $request->sign_request($this->signature_method, $this->consumer, $this->access_token);
        $auth_header = $request->to_header("https://api.linkedin.com&quot ;) ;
        if ($debug) {
          echo $request->get_signature_base_string() . "\n";
          echo $auth_header . "\n";
        }
        $response = $this->httpRequest($status_url, $auth_header, "PUT", $xml);
        return $response;
      }
    

    This took me a while to debug so thought i’d save others the trouble.

  32. mahmud ahsan April 22, 2010 at 12:08 pm #

    @Jarrod, Thanks you’ve noticed that. I also noticed that and fixed that but in another project.

    Checkout my open source project.
    http://thinkdiff.net/facebook/open-source-facebook-twitter-linkedin-status-update-application/

  33. Kunal April 28, 2010 at 9:22 pm #

    The code above seems to be working fine and I get my response in $xml_response.
    Example of XML code I see when I do view source on the page is:

    Kunal
    ……

    How do I parse out data from this to display on the page?

    So if I want to get First name from above and display on my page as :
    First Name: Kunal

  34. mahmud ahsan April 28, 2010 at 9:48 pm #

    @Kunal, you can use php’s simple xml to parse xml data

  35. Kunal April 28, 2010 at 10:29 pm #

    Hi,
    I tried it but could not get it exactly. Here is my xml when I do view source. How can I assign the firstname and lastname to varaibles so I can output it as I need on my page?

    Kunal
    Punwani

  36. mahmud ahsan April 28, 2010 at 11:07 pm #

    @Kunal, its very easy.

    $xml_response = $linkedin->getProfile("~:(id,first-name,last-name,headline,picture-url,public-profile-url)");
    
    $data = simplexml_load_string($xml_response);
    
    <table border="0" cellspacing="3" cellpadding="3">
        <tr><td>Name</td>          <td><a target="_blank" href="<?=$data->{'public-profile-url'}?>"><?=$data->{'first-name'}?> <?=$data->{'last-name'}?></a></td></tr>
         <tr><td>Headline</td>      <td><?=$data->headline?></td></tr>
         <tr><td>Profile Image</td> <td><img src="<?=$data->{'picture-url'}?>" alt="" /></td></tr>
    </table>
    

    You can check my another article http://thinkdiff.net/facebook/open-source-facebook-twitter-linkedin-status-update-application/ and could check the demo to see how I show user info.

    • Gijs March 22, 2011 at 8:49 pm #

      hello Mahmud
      i got this working with simplexml but i can’t get a level deeper, for instance: date-of-birth it consists out of , and

      if tried:
      {‘date-of-birth->day’}?>
      date-of-birth->day; ?> and al kind of different ways…

      • Gijs March 22, 2011 at 8:55 pm #

        sorry right after i posted the question i saw the light:
        {‘date-of-birth’}->day ?>
        thanks anyway and thanks for the great script

  37. Kunal April 29, 2010 at 4:08 am #

    Thanks alot Mahmud Ahsan. This is very useful.

  38. Kunal April 29, 2010 at 5:30 pm #

    Is there a way to retrieve the Contact Settings for a user thru the LinkedIn API?

    For example, I want to be able to retrieve the following:

    Interested In:
    career opportunities
    consulting offers
    reference requests
    getting back in touch

  39. mahmud ahsan April 29, 2010 at 6:41 pm #

    @Kunal, I think currently linkedin yet not open those fields for user. I just checked from here http://developer.linkedin.com/docs/DOC-1002

  40. RW May 29, 2010 at 12:24 am #

    Anybody had trouble running this on Yahoo! Domains?

    I can’t get auth.php to do anything. There is no error msg but I can tell it stops at the ‘include_once “linkedin.php”;’ since I can echo a debug statement before that line but not after.

    Thoughts?

  41. ravi July 1, 2010 at 3:09 pm #

    Great post! thanks

  42. james July 8, 2010 at 5:40 pm #

    Dear mahmud ahsan,
    Thanks.. so far work!!!!!
    Can you please tell me how I can re-use the access-token of a user of linked to update status without login second time at linkedin.

    Like your twitter Demo…

    • mahmud ahsan July 10, 2010 at 1:53 pm #

      You can save the access token in your database, but in linkedin access token has expiration date like 1 day or 2 week. So after that time your token will expire. So you’ve to cleverly code to solve this problem.

  43. posinadh July 16, 2010 at 7:35 pm #

    Advance thanks……..for tutorial…
    … can u give the same explanation by using java………in all links they are giving in php……..but we are developing our application in java…..so please give reply………..

    • mahmud ahsan July 16, 2010 at 10:16 pm #

      I don’t work on java based web application development. So I’m sorry.

  44. Viren August 5, 2010 at 2:24 pm #

    Hi,

    Thanks for the useful code. I followed all the steps that you mentioned in above but when I run ‘auth.php’ it gives me below message : “http 500 internal server error”.

    I am using enginisite local web server.Below are the details,

    $config['base_url'] = ‘http://127.0.0.1:8080/Project/auth.php’;
    $config['callback_url'] = ‘http://127.0.0.1:8080/Project/demo.php’;

    I am new to php so would need your help to understand where I am going wrong. Thanks..

    Kind Regards,
    Viren

    • mahmud ahsan August 5, 2010 at 2:20 pm #

      Please use use the code in hosting server not in localhost.

  45. Viren August 13, 2010 at 11:10 am #

    Hi Mahmud,
    Thanks for helping me out on my issue.

    Now when I execute it , while diverting to the linkedin site it givs below error,

    We were unable to find the authorization token

    I have passed both the keys correctly. What may be the problem.

    Thanks,
    Viren

  46. Ali August 17, 2010 at 3:22 pm #

    Greetings,
    Mahmud, This is great article; very easy and simple to implement OAuth Linkedin.

    I am using it and I am getting the profile information. Currently I am indulged in Messaging API; I want to implement it. It suppose to POST the xml.
    I tried same as setstatus function is implemented for posting xml, but I think setstatus is working. As it is not posting xml i guess; but i can be wrong :) ..
    Do you know how to do it for messaging xml? how can i post it.
    Here is document link from where i m getting assistance.

    http://developer.linkedin.com/docs/DOC-1044

    Pardon my knowledge of PHP, I am new in it :-s

    Thanks

    • Ali August 17, 2010 at 5:41 pm #

      Thank you i have got the solution :) ; we just need to post data in httprequest($var1,$var2,var3,$xmlbody) in callback method..
      xml is below..

      $bodyofxml= Congratulations! you have sent the message, now try to send it to someone else You’re certainly the best person for the job! ;

      request->httprequest(,,,$bodyofxml);
      and thats it :D

      Thanks again Mehmud;

      Now if you see this post, just let me know at how much extent you modified this oauth.php file from the google source code ??

  47. Julia August 20, 2010 at 10:16 pm #

    Hi,

    I tested the code on the server, but it showed error:
    “My Profile Info

    404
    1282320837023
    0
    Could not find person based on: ~

    Performing search for: ?company=facebook&count=10

    Look people who worked in facebookSimpleXMLElement Object
    (
    [status] => 404
    [timestamp] => 1282320837091
    [error-code] => 0
    [message] => Could not find person based on:
    )

    Do you know what is wrong? I didn’t change anything of the code except the consumer key, integrate url, redirect url and consumer secret key.

    Thank you very much

    • umar baig May 1, 2011 at 3:55 pm #

      HOw you solve this problem?
      I am facing this problem
      My Profile Info

      404
      1304243686623
      0
      Could not find person based on: ~

      Performing search for: ?company-name=facebook&count=10

      Look people who worked in facebookSimpleXMLElement Object
      (
      [status] => 400
      [timestamp] => 1304243687349
      [error-code] => 0
      [message] => Unknown key {} for collection field {Root.people}
      )

  48. des August 25, 2010 at 3:49 pm #

    Hi! . i am really new to this and i’ve been reading your post since i’ve started working on it… You said that I can edit it and create a new function such as the invite function. I am trying to create a sndMessage function to send message to a particular user, but it seems not to be working… Please look at my code below.. Thank you in advance. :)

    function sndMessage($msgrecipient) {
    $msg_url = $this->base_url . “/v1/people

    $msgxml = “Good dayI hope you are doing well :) ”;

    $request = OAuthRequest::from_consumer_and_token($this->consumer, $this->access_token, “POST”, $msg_url);
    $request->sign_request($this->signature_method, $this->consumer, $this->access_token);
    $auth_header = $request->to_header(“https://api.linkedin.com”);
    if ($debug) {
    echo $auth_header . “\n”;
    }
    $response = $this->httpRequest($msg_url, $auth_header, “POST”, $msgxml);
    return $response;
    }

  49. des August 25, 2010 at 3:58 pm #

    Hi ali,
    are you trying to create a function that can send message to some of your contacts? can you share it? i’m also new in php and linkedin apis..

    like what did you edit? you copied the setstatus function?

    thanks!!

  50. alexandre September 7, 2010 at 9:37 pm #

    I’m getting also “We were unable to find the authorization token”. Any solution for this?

    Thanks on advance.

    Alexandre

  51. Keegan October 31, 2010 at 3:33 pm #

    Thanks for another great tutorial Mahmud. It was very helpful.

    If anyone is having problems generating an authorize URL on a localhost server, it could be a problem with the CURL function in linkedinOAuth.php

    I am using MAMP for my localhost server and couldn’t generate an authorize URL until I added this to line 123:

    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);

    • mahmud ahsan October 31, 2010 at 4:17 pm #

      Thank You for your information.

    • umar baig May 1, 2011 at 4:29 am #

      I am using wamp on localhost I have problem in auth.php(Fatal error: Call to undefined function curl_init())

      and demo.php(
      Notice: Undefined index: requestToken
      Notice: Undefined index: oauth_verifier
      Notice: Undefined index: oauth_access_token
      Notice: Undefined variable: debug
      Fatal error: Call to undefined function curl_init())

      Kindly reply urgently It is my first task in First Job.

      • mahmud ahsan May 1, 2011 at 12:19 pm #

        Checkout the code from linux server.

      • umar baig May 1, 2011 at 12:25 pm #

        Problem is solved for CURL in localhost using WAMP
        Go to C:\wamp\bin\apache\Apache2.2.17\bin\php.ini
        remove ; of php_curl and restart WAMP SERVICES.

        but problem exists in demo.php(
        Notice: Undefined index: requestToken
        Notice: Undefined index: oauth_verifier
        Notice: Undefined index: oauth_access_token
        Notice: Undefined variable: debug)

  52. Faruk November 21, 2010 at 4:13 pm #

    I read your article and tried to implement for codeigniter .
    I need linkedin user permanent access. I used your codes (demo.php) in my controller.

    Now how can I get permanent access token ? which I want save in database for long time use.

    • mahmud ahsan November 22, 2010 at 12:57 am #

      Please save oauth_access_token and oauth_verifier and requestToken in your database. But normally after giving access oauth_access_token and requestToken become same. And next time when you initialize the linkedin class object first check if these tokens are in your database or not. If these tokens are in your database then retrieve them from database and initialize the linkedin object.

  53. Fabian Ramirez December 2, 2010 at 8:24 am #

    Very good work

  54. jim fragile December 16, 2010 at 11:59 am #

    Hi, can this be possible integrating linkedin login wordpress blog??what is the easiest way?thanks

    • mahmud ahsan December 16, 2010 at 9:56 pm #

      Why not, develop a plugin using linkedin api.

  55. Cees December 31, 2010 at 10:22 pm #

    Good stuff!! Work like a charm…

    2 small questions:

    1. doing a status update (already figured out that line 99 in linkedin.php was wrong by the way), where would I find that on my linkedIN page? I realize this is more a LinedIN howto question than an API question….
    2. Can anyone point me in the right direction of doing a “network update” instead of “status update”? I took the setStatus-func and change the url from current-status to person-activities, but no luck….

    Thanks,

    all help appreciated

    Cees

  56. mahmud ahsan January 1, 2011 at 1:02 am #

    Cees, status update api is deprecated please check there new documentation regarding api. And also you could check my another article http://thinkdiff.net/php/integrate-linkedin-api-part-2/

  57. Cees January 1, 2011 at 6:09 pm #

    You are my hero!!! The share-function in part 2 was exactly what I was looking for!!!

  58. Summer Apparels January 3, 2011 at 11:52 am #

    Hello
    this post is very informative
    i like this post
    thanks for sharing knowledge,

  59. Rakesh Ranjan January 10, 2011 at 7:36 pm #

    Hi Mahmud,

    I get a message status updated successfully, but can’t see my status updated on facebook or linked in. Does the status gets changed immediately or it takes time ?

    Regards
    Rakesh

    • Ganesh Mane April 6, 2012 at 7:50 pm #

      I want C# code to get basic user information from linkedIn using linkedIn API’s.

  60. Ankur January 11, 2011 at 6:28 pm #

    @Mahmud

    hi,

    i can get the linked in authorisation page but after logging in, i get the following error:

    Warning: Cannot modify header information – headers already sent by (output started at /home/content/86/6578386/html/demo/linkedin.php:133) in /home/content/86/6578386/html/demo/act_demo.php on line 18

    i dont know why this happening..i have followed the code as it is, without any changes.plz help

  61. Ben January 13, 2011 at 9:47 pm #

    @mahmud ahsan is it possible to zip up all your files i.e. auth.php, demo.php, linkedin.php and oAuth.php

    I have a feeling there are some problems when people are getting the newer oAuth.php files from external sources etc.

    Thanks

  62. muhammad.jamil January 14, 2011 at 5:15 pm #

    Please tell me why I am getting this error

    401 1295003706554 0 [unauthorized]. No consumer found for key.

  63. Abhay February 15, 2011 at 8:08 pm #

    I was facing “We were unable to find the authorization token” while deploying in ubuntu .
    Things were fine in debian.

    I am using new linkedin apis.
    Solution:
    open linkedin.php
    in the httpRequest function add:
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);

    I also changed ubuntu timezone to EST using follow command:
    ln -sf /usr/share/zoneinfo/EST localtime

    This erros should be fixed and linkedin should return request token.

  64. Yasir February 18, 2011 at 3:57 pm #

    Thanks a lot, Ahsan this is very useful. I need to know, how I can get Current Position, Language, Location and Company.

    And also please tell me if i get xml through API like this

    Taylor
    Singletary
    Technical Evangelist at LinkedIn

    http://www.linkedin.com/profile?viewProfile=&key=3308337&authToken=REQa&authType=name


    how i will read it through PHP i mean how to assign these values to variable.

    Thanks in anticipation.

  65. Yasir February 18, 2011 at 3:59 pm #

    my code was parsed in last post in fact i actually want to do that which coincidentally happened when submitting post here. I try to publish my code again with code tag.

    Taylor
    Singletary
    Technical Evangelist at LinkedIn

    http://www.linkedin.com/profile?viewProfile=&key=3308337&authToken=REQa&authType=name

  66. Gitesh Dang February 21, 2011 at 8:54 pm #

    Hi Mahmuud, How can i print or echo only first name from XM_response.
    In the above example there are all values printed but i need those values at different place one by one like
    First name :
    ******some text
    ******
    Last Name :
    ********some text
    ******
    How can i get one by one value from all values…?
    Waiting For your response..
    Thanks

    • mahmud ahsan February 21, 2011 at 9:22 pm #

      Hey man, using xml parsing you can easily parse the xml output to get name. So learn simplexml of php to parse xml.

      • Gitesh Dang February 21, 2011 at 11:02 pm #

        @mahmud thanks for response..actualy i dont have time to create manualy in Socialengine4 environment..So i need module for socialengine4.. I knw about XML but its urgent thats y m finding..so pleas help me yar..

  67. akil March 15, 2011 at 3:25 pm #

    hi mahmud,
    i need to update the status from an asp.net application.. can you post the source code for this. Please am in urgent need for this:( i lll be much thankful to you… pls help me out

    • kcjagadeep June 21, 2011 at 8:34 pm #

      Akil,
      U got any idea for Asp.net ??

  68. Katy May 1, 2011 at 1:31 pm #

    Hi! You look like you can understand all this linkedIN api stuff;;

    Can you tell me if it is possible for me to display my own linkedIN recommendations on my website without anyone having to be logged into LinkedIN to see them?

    I want them to show up just like my testimonials do here : http://go-etree.com/testimonials.

    Please let me know if it is possible and where I should start looking to figure it out! Thanks!

    • mahmud ahsan May 2, 2011 at 1:10 am #

      Please check linkedin documentation, I worked on linkedin api long ago.

  69. Santosh May 2, 2011 at 5:15 pm #

    Hi,
    I want to create a login page in our site and after login from my site i get the information in my site of my friends.

    How it will do??

    Please solve my problem.
    If you have code the provide me also.

    Thanks

  70. Muhammad Zafar May 19, 2011 at 2:43 am #

    @mahmud your code working perfectly fine on localhost. Thanks for sharing.

  71. manish May 19, 2011 at 12:50 pm #

    hi

    how can i get an access to inbox and filter the messages on the basis of keywords

  72. manish May 19, 2011 at 1:09 pm #

    I want to make app for filtering messages from your inbox on basis of keywords.

  73. Dwaine May 20, 2011 at 1:56 am #

    I want to show my linkedin group discussion articles on my website. Can I get a rss feed from the LI group discussion list? is there a better way. Oh, also our new website is being built on sharepoint platform.

  74. kcjagadeep June 21, 2011 at 8:36 pm #

    Any one have the link or update about the same kind of project in ASP.Net or C# ???

  75. chandan July 3, 2011 at 4:42 pm #

    @mahmud ahsan: great work..
    @alvin: i was also facing the same issue while accessing the linkedin api (https), i found a solution at this link “http://unitstep.net/blog/2009/05/05/using-curl-in-php-to-access-https-ssltls-protected-sites” though it is not a safe method but it works for me.

  76. bm August 1, 2011 at 5:00 pm #

    i didn’t get OAuth.php and linkedin.php files can u please send OAuth.php and linkedin.php
    my id (bikeshm@gmail.com)

  77. Ajay September 12, 2011 at 2:09 pm #

    Hi mahmud ahsan

    Good Job

    I have one confusion . how can i implement this code in zend framework .

    please explain me step by step.

    Thanks

  78. vinoy September 15, 2011 at 6:25 pm #

    @mahmud can you tell is any post function is availsble ( message posted to another users linkedin account) like $search_response = $linkedin->search(“?company-name=facebook&count=10″);

    • mahmud ahsan September 19, 2011 at 1:28 am #

      Using linkedin api you can send message to other linkedin user. I don’t know what you mean by message post.

  79. Jyotirmay Intellisense September 19, 2011 at 6:11 pm #

    hi mahmud ahsan, i want to know how to integrate this apps to wordpress site. these files are opensource and thanks for share but please let me know more about to how to pull data from linkedin profile to my website or other…

    • mahmud ahsan September 20, 2011 at 1:46 am #

      You have to create wordpress plugin for your purpose.

  80. Roy Vincent September 23, 2011 at 1:56 pm #

    is there a widget to display the update of the specific user into the website just like in twitter the tweets are displayed in websites

  81. Adam October 5, 2011 at 9:08 pm #

    Great post! Thanks for sharing. This has really helped me today :)

  82. amrish October 14, 2011 at 11:51 am #

    Hello There

    thanks for your great post its help us to much

    but i have one problem how can i integrate that in my Social Engine CMS.http://mxicoders.in/linked/home.php

    i want to show the Linkedin News feed in my home page for particular users.

    Thanks
    Amrish

  83. ravi October 14, 2011 at 12:14 pm #

    Thank you sir..
    This is really a helpful guide for linkedin API’s integration…:)

  84. Roy Vincent October 20, 2011 at 6:06 am #

    best tuts for linkedin integration! thanks thanks!

  85. Shiv November 8, 2011 at 6:44 pm #

    Really Good Tutorial Mahmud………………keep it up!!!!!!!!!!!!!

  86. ranjith November 9, 2011 at 4:55 pm #

    Hi,

    Can anyone of you please mail me the zipped file of this properly working project..

    I need it immediately for learning purposes.

    My Email is is ranjithshenoy215@gmail.com

    Help in this regard will be highly appreciated.

    Thanks.

  87. charu November 9, 2011 at 5:24 pm #

    Hi,

    I need to create a web app in which we can read a particular person’s name from a text box and then extract relevant information of that person from Linkedln.

    Please reply soon.

    Thanks

  88. seocosenza November 14, 2011 at 3:06 am #

    Hi mahmud,
    your tutorial really rock! :)
    I have a question for you: i do not have cURL in my settings, and how can i use your code without cURL support?

    thank you very much in advance,
    andrea :)

    • mahmud ahsan November 17, 2011 at 2:37 pm #

      Hello,
      I’m not sure, in that case you may have to use socket. But in that case you may need to update the linkedin code.

  89. Smrithi December 2, 2011 at 11:09 am #

    Is there a way to display sample application on Linkedin wall as that of slideshare?It is kind of urgent pls let me know sooooonnnn:/

  90. kevin December 13, 2011 at 8:53 pm #

    hey,my simple demo working on localhost..
    but when i put it to the server..
    it gives an error..
    so please let me know how should i change so that it can work properly..

    Server error
    The website encountered an error while retrieving http://www.mydomain.com/invite. It may be down for maintenance or configured incorrectly.
    Here are some suggestions:
    Reload this webpage later.
    HTTP Error 500 (Internal Server Error): An unexpected condition was encountered while the server was attempting to fulfill the request…

    and not showing any content..

    thanx in advance

  91. someone December 16, 2011 at 3:21 am #

    i wan to know if i can modify the styles of the api, for example width and all of that

  92. matrimoni December 18, 2011 at 5:39 pm #

    Very good article…thank you!…

  93. kumar December 28, 2011 at 3:28 pm #

    Hi

    how to post a job from site to linkedin. please anybody have a sample code.

  94. kumar December 28, 2011 at 3:29 pm #

    hi

    how to post a job from site to linkedin. please anybody have a sample code. using java

  95. jigar January 11, 2012 at 6:53 pm #

    Hi,

    can any one help me out with how to make a post in a group?

    i tried the same way its mentions in update user status….
    added the required attributes in xml format

    but its making any post in group …… and also m not getting any error…….

  96. Vivek February 9, 2012 at 12:02 pm #

    I can not post status with this app……..can any one help

  97. navjot April 4, 2012 at 11:28 am #

    hello!

    http:192.168.0.2:11016/demo.php?oauth_token=1a58a8ae-a712-4b6a-93c5-092558958951&oauth_verifier=24241

    where to put this ???
    reply soon

    • navjot April 4, 2012 at 3:33 pm #

      how can we import connections ?

  98. navjot April 4, 2012 at 3:35 pm #

    how can we import connections??

  99. ravindran April 5, 2012 at 1:05 pm #

    the link http://developer.linkedin.com/docs/DOC-1005 is not available.. pls change/remove dat…

  100. David Thomas April 20, 2012 at 10:56 am #

    I really like this useful information and I would like to share my community because they are still waiting this kinds of api for linkedin….

  101. Kapil Garg April 20, 2012 at 10:58 am #

    Hi Mahmud,

    This is informatics article, I really like the post shared by you. I need also access of permanent users in LinkedIn. I obtain a message status updated successfully, but can’t see yet my status updated on Facebook or linked in. Please suggest me it would be immediately or it takes time?
    Thanks for sharing.

Leave a Reply