Integration with Part 2

In a previous article we took an initial look at how a business-oriented community website can benefit from integrating with, outlining the steps necessary to utilize the LinkedIn API and OAuth to do this. Now we’ll look more deeply at the achievement of integration and the ability to allow your users to invite LinkedIn members directly to your website. The library that we are using and that we referred to in our previous artcle, is this one.

So, again, this integration task consists of two parts: first, the user must search for a friend whom they wish to invite to your site and then the invitation must be sent.

1. The search function is outlined very well in the LinkedIn API documentation so we’ll skip here directly to a simple example in order to highlight the most important features:

//searching of all friends named Ann

$search_response = $linkedin->search("?facets=network&facet=network,F&first-name=Ann");

$xml = simplexml_load_string($search_response);

foreach($xml->people->person as $person)

Take special note:

  • All parameters of a search inquiry are connected with logical AND.

2. Unfortunately LinkedIn does not allow us to detect the email address of a user but invitations can be sent via LinkedIn’s on-site messaging system. While the API will allow us to send on-site messages, the feature is not implemented in the linkedin.php library which we’ve loaded and so we’ll need to modify a bit. Add this code into the file linkedin.php:

  • WildCard is not supported.
  • If a search returns too many results you are able to narrow them done using the “total” parameter in the returned XML:
base_url . "/v1/people/~/mailbox";
$request = OAuthRequest::from_consumer_and_token($this->consumer, $this->access_token, "POST", $send_url);
$request->sign_request($this->signature_method, $this->consumer, $this->access_token);
$auth_header = $request->to_header("");

if ($this->debug) {
echo $request->get_signature_base_string() . "\n";
echo $auth_header . "\n";

$raw_xml = "

$status = 0;
$response = $this->httpRequest($send_url, $auth_header, "POST", $raw_xml, $status);

return $status;

Now the code to send the message will look like this:

//$id_rec - id recipient in LinkedIn.
$send_response = $linkedin->sendMessage($id_rec, 'Subject', 'Message body');

if($send_response == 201)
//Message sended
//Error handling
This entry was posted in PHP Tips.

Comments are closed.