<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>
<channel>
	<title>Michael Tikhonin - Web-Programmer and Consultant</title>
	<atom:link href="http://phpclimber.com/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://phpclimber.com</link>
	<description></description>
	<lastBuildDate>Fri, 09 Nov 2012 21:19:57 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.4.2</generator>
		<item>
		<title>Integration with LinkedIn.com Part 2</title>
		<link>http://phpclimber.com/?p=23</link>
		<comments>http://phpclimber.com/?p=23#comments</comments>
		<pubDate>Thu, 02 Dec 2010 08:12:27 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP Tips]]></category>
		<guid isPermaLink="false">http://phpclimber.com/?p=23</guid>
		<description><![CDATA[In a previous article we took an initial look at how a business-oriented community website can benefit from integrating with LinkedIn.com, outlining the steps necessary to utilize the LinkedIn API and OAuth to do this. Now we&#8217;ll look more deeply at the achievement of integration and the ability to allow your users to invite LinkedIn [...]]]></description>
			<content:encoded><![CDATA[<p>In a previous article we took an initial look at how a business-oriented community website can benefit from integrating with <a href="http://linkedin.com/">LinkedIn.com</a>, outlining the steps necessary to utilize the LinkedIn API and OAuth to do this. Now we&#8217;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 <a href="http://developer.linkedin.com/servlet/JiveServlet/download/3005-1178/LinkedInOAuth-PHP-WithSearch.zip;jsessionid=8AD7DC6FC927780812298C29BF7F2217.node0">this one</a>.</p>
<p>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.</p>
<p><span id="more-23"></span></p>
<p>1. The search function is outlined very well in the LinkedIn <a href="http://developer.linkedin.com/docs/DOC-1191">API documentation</a> so we&#8217;ll skip here directly to a simple example in order to highlight the most important features:</p>
<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//searching of all friends named Ann</span>
&nbsp;
<span style="color: #000088;">$search_response</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$linkedin</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>search<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;?facets=network&amp;amp;facet=network,F&amp;amp;first-name=Ann&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$xml</span> <span style="color: #339933;">=</span> <span style="color: #990000;">simplexml_load_string</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$search_response</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$xml</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>people<span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>person <span style="color: #b1b100;">as</span> <span style="color: #000088;">$person</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
<span style="color: #990000;">print_r</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$person</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>
<p>Take special note:</p>
<ul>
<li>All parameters of a search inquiry are connected with logical AND.</li>
</ul>
<p>2. Unfortunately LinkedIn does not allow us to detect the email address of a user but invitations can be sent via LinkedIn&#8217;s on-site messaging system. While the API will allow us to send <a href="http://developer.linkedin.com/docs/DOC-1044">on-site messages</a>, the feature is not implemented in the linkedin.php library which we&#8217;ve loaded and so we&#8217;ll need to modify a bit. Add this code into the file linkedin.php:</p>
<ul>
<li>WildCard is not supported.</li>
<li>If a search returns too many results you are able to narrow them done using the &#8220;total&#8221; parameter in the returned XML:</li>
</ul>
<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">base_url <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;/v1/people/~/mailbox&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$request</span> <span style="color: #339933;">=</span> OAuthRequest<span style="color: #339933;">::</span><span style="color: #004000;">from_consumer_and_token</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>consumer<span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>access_token<span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;POST&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$send_url</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$request</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>sign_request<span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>signature_method<span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>consumer<span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>access_token<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$auth_header</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$request</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>to_header<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;https://api.linkedin.com&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>debug<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$request</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>get_signature_base_string<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$auth_header</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000088;">$raw_xml</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;
&nbsp;
  <span style="color: #006699; font-weight: bold;">$subj</span>
  <span style="color: #006699; font-weight: bold;">$msg</span>
&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$status</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$response</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>httpRequest<span style="color: #009900;">&#40;</span><span style="color: #000088;">$send_url</span><span style="color: #339933;">,</span> <span style="color: #000088;">$auth_header</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;POST&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$raw_xml</span><span style="color: #339933;">,</span> <span style="color: #000088;">$status</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">return</span> <span style="color: #000088;">$status</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
?<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span></pre></div></div>
<p>Now the code to send the message will look like this:</p>
<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//$id_rec - id recipient in LinkedIn.</span>
<span style="color: #000088;">$send_response</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$linkedin</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>sendMessage<span style="color: #009900;">&#40;</span><span style="color: #000088;">$id_rec</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Subject'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Message body'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$send_response</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">201</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
<span style="color: #666666; font-style: italic;">//Message sended</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">else</span>
<span style="color: #009900;">&#123;</span>
<span style="color: #666666; font-style: italic;">//Error handling</span>
<span style="color: #009900;">&#125;</span></pre></div></div>
]]></content:encoded>
			<wfw:commentRss>http://phpclimber.com/?feed=rss2&#038;p=23</wfw:commentRss>
		<slash:comments>252</slash:comments>
		</item>
		<item>
		<title>Integration with LinkedIn.com Part 1</title>
		<link>http://phpclimber.com/?p=10</link>
		<comments>http://phpclimber.com/?p=10#comments</comments>
		<pubDate>Wed, 01 Dec 2010 19:39:56 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP Tips]]></category>
		<guid isPermaLink="false">http://phpclimber.com/?p=10</guid>
		<description><![CDATA[If your site is a business-oriented community, consider integrating it with LinkedIn.com in order to draw targeted, business-minded visitors and members. Given LinkedIn’s focus on business and technical professionals, it is an excellent potential source of social traffic to your site; simply adding an &#8220;invite friends&#8221; button from LinkedIn will allow you to draw IT [...]]]></description>
			<content:encoded><![CDATA[<p>If your site is a business-oriented community, consider integrating it with <a href="http://linkedin.com/">LinkedIn.com</a> in order to draw targeted, business-minded visitors and members. Given  LinkedIn’s focus on business and technical professionals, it is an  excellent potential source of social traffic to your site; simply adding  an &#8220;invite friends&#8221; button from LinkedIn will allow you to draw IT and  business specialists directly from LinkedIn to your website.</p>
<p>Talking about &#8220;integrating&#8221; is one thing; how does one integrate in practice? LinkedIn provides its members with a simple, <a href="http://developer.linkedin.com/community/apis">well-documented API</a> to allow for this and other off-site functions. The OAuth protocol,  used by LinkedIn to authorize its account holders, allows you to  integrate the content you create on LinkedIn with your website without  the need to store the account password locally. While working with OAuth  is not necessarily a simple thing, free libraries like <a href="http://developer.linkedin.com/servlet/JiveServlet/download/3005-1178/LinkedInOAuth-PHP-WithSearch.zip;jsessionid=8AD7DC6FC927780812298C29BF7F2217.node0">this one</a> (that I personally use) exist on the web to make the process an easier one.</p>
<p>The first step is to register your site with LinkedIn; this will in  turn provide you with the API key and Secret key, each of which is  needed to proceed. The keys are used to authorize users in these steps:</p>
<p>1. First we’ll create a temporary token for the user; this will later be used until a permanent access token is generated:</p>
<p><span id="more-10"></span></p>
<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$linkedin</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> LinkedIn<span style="color: #009900;">&#40;</span><span style="color: #000088;">$linkedin_api_key</span><span style="color: #339933;">,</span> <span style="color: #000088;">$linkedin_secret_key</span><span style="color: #339933;">,</span> <span style="color: #000088;">$linkedin_callback_url</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$linkedin</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getRequestToken</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>
<p style="text-align: justify;">
<p style="text-align: justify;">
<p>Here, $linkedin_api_key and $linkedin_secret_key are the keys  obtained from LinkedIn upon registering of our application, and  $linkedin_callback_url is the url on your site where the user will be  redirected after authorizing.</p>
<p>Now a Request token is generated and gets in $linkedin-&gt;request_token where it must be retained, for example in a database.</p>
<p>2. Direct the user to a custom URL, formatted with the help of a Request token</p>
<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Location: &quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$linkedin</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">generateAuthorizeUrl</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>
<p style="text-align: justify;">
<p>Here the user will see a form for authorization where they’ll need to  enter their email address and password. Following this, the user will  be redirected back to your site, specifically to an URL which will be  defined when the object is created by LinkedIn.</p>
<p>3. Now we need to create an object called LinkedIn and include within it all of the data necessary to generate an Access Token.</p>
<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$linkedin</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> LinkedIn<span style="color: #009900;">&#40;</span><span style="color: #000088;">$linkedin_api_key</span><span style="color: #339933;">,</span> <span style="color: #000088;">$linkedin_secret_key</span><span style="color: #339933;">,</span> <span style="color: #000088;">$linkedin_callback_url</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$linkedin</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">request_token</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$linkedin</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">oauth_verifier</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'oauth_verifier'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span></pre></div></div>
<p>Here, $ _REQUEST ['oauth_verifier'] is a variable passed by LinkedIn.</p>
<p>4. Now we can generate the Access Token.</p>
<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$linkedin</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getAccessToken</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$oauth_verifier</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>
<p style="text-align: justify;">
<p>The code: $ linkedin-&gt; access_token must be stored in the database for future usage.</p>
<p>All of these actions must be completed only during the first  connection of a user to LinkedIn from your website; in the future, the  same user will be able to connect to LinkedIn using the Access Token in  your database:</p>
<p style="text-align: justify;">
<p style="text-align: justify;">
<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$linkedin</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> LinkedIn<span style="color: #009900;">&#40;</span><span style="color: #000088;">$linkedin_api_key</span><span style="color: #339933;">,</span> <span style="color: #000088;">$linkedin_secret_key</span><span style="color: #339933;">,</span> <span style="color: #000088;">$linkedin_callback_url</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$linkedin</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">access_token</span> <span style="color: #339933;">=</span> <span style="color: #339933;">&lt;</span> obtained from the database <span style="color: #339933;">&gt;;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// obtain data about the user</span>
&nbsp;
<span style="color: #000088;">$xml_response</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$linkedin</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getProfile</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;~:(id,first-name,last-name,headline,picture-url)&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>
]]></content:encoded>
			<wfw:commentRss>http://phpclimber.com/?feed=rss2&#038;p=10</wfw:commentRss>
		<slash:comments>307</slash:comments>
		</item>
	</channel>
</rss>
