{"id":10104,"date":"2013-11-10T13:08:39","date_gmt":"2013-11-10T12:08:39","guid":{"rendered":"http:\/\/flaven.fr\/?p=10104"},"modified":"2013-11-12T06:08:03","modified_gmt":"2013-11-12T05:08:03","slug":"linkedin-api-oauth-se-connecter-et-rapatrier-des-informations-de-la-plate-forme-linkedin","status":"publish","type":"post","link":"https:\/\/flaven.fr\/2013\/11\/linkedin-api-oauth-se-connecter-et-rapatrier-des-informations-de-la-plate-forme-linkedin\/","title":{"rendered":"Linkedin, API, OAuth &#8211; Se connecter et rapatrier des informations de la plate-forme Linkedin"},"content":{"rendered":"<p><!--  Linkedin, API, OAuth - Se connecter et rapatrier des informations de la plate-forme Linkedin  --><br \/>\n\t<!--  Linkedin, API, OAuth, PHP, connexion --><\/p>\n<p>Il y avait au d\u00e9part de cet article, la volont\u00e9 de pouvoir partager correctement des articles sur Linkedin donc d&#8217;impl\u00e9menter le protocole <code>Open Graph<\/code>, le m\u00eame que sur Facebook afin d&#8217;optimiser le partage sur cette plate-forme plus professionnelle.<br \/>\nDe fil en aiguille, nous avons finalement explorer un peu plus profond\u00e9ment l&#8217;API linkedin. C&#8217;est une chose que de partager, c&#8217;est aussi une chose de pouvoir rapatrier de l&#8217;information.<\/p>\n<p><i>Pour m\u00e9moire, on avait consacr\u00e9 un billet \u00e0 ce fameux <code>Open Graph protocol<\/code> qui facilite le partage sur Facebook <\/i><\/p>\n\t\t\t\t\t<div class=\"textwidget-unique text\">\n\n\t\t\t\t\t        <div class=\"textwidget-photo\">\n\t\t\t\t\t                <a href=\"https:\/\/flaven.fr\/books\/mining-the-social-web\/\" class=\"photo\" title=\"Mining the Social Web\"><img loading=\"lazy\" decoding=\"async\" alt=\"Mining the Social Web\" src=\"http:\/\/ecx.images-amazon.com\/images\/I\/51iY2aVuWSL._SL160_.jpg\" width=\"122\" height=\"160\"><\/a>\n\t\t\t\t\t            <\/div>\n\t\t\t\t\t\t<div class=\"info half\">\n\t\t\t\t\t\t\t<h2 class=\"product-title\"><a class=\"head\" href=\"https:\/\/flaven.fr\/books\/mining-the-social-web\/\" title=\"Mining the Social Web\">Mining the Social Web<\/a><\/h2>\n\t\t\t\t\t\t\t\n\t\t\t\t\t        <p class=\"product-excerpt\">Un excellent livre pour exercer une surveillance de votre notori\u00e9t\u00e9 digitale sur les r\u00e9seaux sociaux (Twitter, Facebook, linkedin) en \"hackant\" directement les APIs. Rie,n de tel pour se constituer un tableau de bord de votre notori\u00e9t\u00e9 digitale sur les r\u00e9seaux.<\/p>\n\t\t\t\t\t\t\t\tGenre(s) : <a href=\"https:\/\/flaven.fr\/book-type\/api\/\" rel=\"tag\">API<\/a>, <a href=\"https:\/\/flaven.fr\/book-type\/direction-de-projet-agile\/\" rel=\"tag\">Direction de projet<\/a>, <a href=\"https:\/\/flaven.fr\/book-type\/facebook\/\" rel=\"tag\">Facebook<\/a>, <a href=\"https:\/\/flaven.fr\/book-type\/linkedin\/\" rel=\"tag\">Linkedin<\/a>, <a href=\"https:\/\/flaven.fr\/book-type\/marketing-digital\/\" rel=\"tag\">Marketing<\/a>, <a href=\"https:\/\/flaven.fr\/book-type\/methodologie\/\" rel=\"tag\">m\u00e9thodologie<\/a>, <a href=\"https:\/\/flaven.fr\/book-type\/marketing-multicanal\/\" rel=\"tag\">Multicanal<\/a>, <a href=\"https:\/\/flaven.fr\/book-type\/referencement\/\" rel=\"tag\">R\u00e9f\u00e9rencement<\/a>, <a href=\"https:\/\/flaven.fr\/book-type\/reseaux-sociaux-partage-prescription\/\" rel=\"tag\">R\u00e9seaux Sociaux<\/a>, <a href=\"https:\/\/flaven.fr\/book-type\/roi-roiste\/\" rel=\"tag\">ROI<\/a>, <a href=\"https:\/\/flaven.fr\/book-type\/smo\/\" rel=\"tag\">SMO<\/a>, <a href=\"https:\/\/flaven.fr\/book-type\/twitter\/\" rel=\"tag\">Twitter<\/a><br>Auteur(s) : <a href=\"https:\/\/flaven.fr\/book-author\/matthew-a-russell\/\" rel=\"tag\">Matthew A. Russell<\/a><br>Edition(s) : <a href=\"https:\/\/flaven.fr\/book-description\/oreilly\/\" rel=\"tag\">O'Reilly<\/a><br>\n\t\t\t\t\t<div class=\"but-wrap\"><a href=\"http:\/\/www.amazon.fr\/Mining-Social-Web-Matthew-Russell\/dp\/1449388345%3FSubscriptionId%3DAKIAJYB2QGGQOTHQLRPA%26tag%3Dhecubenet-21%26linkCode%3Dxm2%26camp%3D2025%26creative%3D165953%26creativeASIN%3D1449388345\" class=\"button\"><span><i class=\"more\"><\/i>+ d'infos<\/span><\/a><\/div>\n\t\t\t\t\t\t<\/div>\n\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t\t\t\t\t\t\t\t\n<ul>\n<li>Facebook, Open Graph protocol, Partage, R\u00e9seau social \u2013 Les bonnes pratiques pour le partage social sur Facebook<br \/><a href=\"https:\/\/flaven.fr\/2012\/04\/facebook-open-graph-protocol-partage-reseau-social-les-bonnes-pratiques-pour-la-partage-social-sur-facebook\/\" target=\"_blank\">https:\/\/flaven.fr\/2012\/04\/facebook-open-graph-protocol-partage-reseau-social-les-bonnes-pratiques-pour-la-partage-social-sur-facebook\/<\/a><\/li>\n<\/ul>\n<p><b>D&#8217;\u00e9vidence, en comparaison avec l&#8217;API Twitter, les r\u00e8gles de cr\u00e9ation d&#8217;une API sur Linkedin sont relativement similaires. C&#8217;est le pr\u00e9-requis indispensable pour se connecter \u00e0 l&#8217;API linkedin.<\/b><\/p>\n<h4>Cr\u00e9er une application sur Linkedin<\/h4>\n<p>Voici les principales captures d&#8217;\u00e9cran pour la cr\u00e9ation d&#8217;un app sur l&#8217;API Linkedin sur http:\/\/developer.linkedin.com\/.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" src=\"https:\/\/flaven.fr\/wp-content\/uploads\/2013\/11\/screens_app_1.jpg\" alt=\"Linkedin, API, OAuth - Se connecter et rapatrier des informations de la plate-forme Linkedin\" width=\"500\" height=\"313\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" src=\"https:\/\/flaven.fr\/wp-content\/uploads\/2013\/11\/screens_app_2.jpg\" alt=\"Linkedin, API, OAuth - Se connecter et rapatrier des informations de la plate-forme Linkedin\" width=\"500\" height=\"313\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" src=\"https:\/\/flaven.fr\/wp-content\/uploads\/2013\/11\/screens_app_3.jpg\" alt=\"Linkedin, API, OAuth - Se connecter et rapatrier des informations de la plate-forme Linkedin\" width=\"500\" height=\"313\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" src=\"https:\/\/flaven.fr\/wp-content\/uploads\/2013\/11\/screens_app_4.jpg\" alt=\"Linkedin, API, OAuth - Se connecter et rapatrier des informations de la plate-forme Linkedin\" width=\"500\" height=\"313\" \/><\/p>\n<p><b>Vous obtenez donc les codes n\u00e9cessaires au param\u00e9trage de votre authentification que vous allez utiliser dans votre script.<\/b><\/p>\n<ul>\n<li>Nom de l&#8217;application : test_flaven_oauth<\/li>\n<li>Cl\u00e9 API : msqi8kmf9dy4<\/li>\n<li>Cl\u00e9 secr\u00e8te : RP71sq5fGWwLMbsN<\/li>\n<li>Token utilisateur OAuth : 6c98dcd0-3hg5-7i47-aw0v-0a621b650faI<\/li>\n<li>Secret utilisateur OAuth : d4d824f1-f1a0-1048-7s78-921a87q20MLL<\/li>\n<\/ul>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" src=\"https:\/\/flaven.fr\/wp-content\/uploads\/2013\/11\/screens_oauth_1.jpg\" alt=\"Linkedin, API, OAuth - Se connecter et rapatrier des informations de la plate-forme Linkedin\" width=\"500\" height=\"313\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" src=\"https:\/\/flaven.fr\/wp-content\/uploads\/2013\/11\/screens_oauth_2.jpg\" alt=\"Linkedin, API, OAuth - Se connecter et rapatrier des informations de la plate-forme Linkedin\" width=\"500\" height=\"313\" \/><\/p>\n<p><b>Conclusion : en comparaison de l&#8217;API Twitter, l&#8217;API linkedin semble moins bien document\u00e9. L&#8217;authentification est plus contraignante sans doute parce les donn\u00e9es y sont peut-\u00eatre plus sensibles sur cette plate-forme professionnelle mais enfin on parvient finalement \u00e0 ces fins. La bonne nouvelle c&#8217;est que si vous faites les modifications n\u00e9cessaires pour le partage sur Facebook, les donn\u00e9es <code>Open Graph Protocol<\/code> seront utilis\u00e9es \u00e0 l&#8217;identique sur Linkedin<\/b><\/p>\n<p>\t<b>Un script d&#8217;authentification et de rapatriement des donn\u00e9es de votre compte Linkedin.<\/b><\/p>\n<pre lang=\"php\">\r\n\t  &lt;?php\r\n    \/\/ Change these\r\n    \/\/ define('API_KEY',      'YOUR_API_KEY_HERE'                                          );\r\n    \/\/ define('API_SECRET',   'YOUR_API_SECRET_HERE'                                       );\r\n    \/* To change with your own credentials *\/\r\n    define('API_KEY',      'msqi8kmf9dy4'                                          );\r\n    define('API_SECRET',   'RP71sq5fGWwLMbsN'                                       );\r\n\r\n\r\n\r\n    define('REDIRECT_URI', 'http:\/\/' . $_SERVER['SERVER_NAME'] . $_SERVER['SCRIPT_NAME']);\r\n    define('SCOPE',        'r_fullprofile r_emailaddress rw_nus'                        );\r\n\r\n    \/\/ You'll probably use a database\r\n    session_name('linkedin');\r\n    session_start();\r\n\r\n    \/\/ OAuth 2 Control Flow\r\n    if (isset($_GET['error'])) {\r\n        \/\/ LinkedIn returned an error\r\n        print $_GET['error'] . ': ' . $_GET['error_description'];\r\n        exit;\r\n    } elseif (isset($_GET['code'])) {\r\n        \/\/ User authorized your application\r\n        if ($_SESSION['state'] == $_GET['state']) {\r\n            \/\/ Get token so you can make API calls\r\n            getAccessToken();\r\n        } else {\r\n            \/\/ CSRF attack? Or did you mix up your states?\r\n            exit;\r\n        }\r\n    } else { \r\n        if ((empty($_SESSION['expires_at'])) || (time() &gt; $_SESSION['expires_at'])) {\r\n            \/\/ Token has expired, clear the state\r\n            $_SESSION = array();\r\n        }\r\n        if (empty($_SESSION['access_token'])) {\r\n            \/\/ Start authorization process\r\n            getAuthorizationCode();\r\n        }\r\n    }\r\n     \r\n    define ('_SOURCE_LINKEDIN_', '\/v1\/people\/~:(id,first-name,last-name,headline,industry)');\r\n\r\n    $user = fetch('GET', ''._SOURCE_LINKEDIN_.'');\r\n    \/\/ http:\/\/api.linkedin.com\/\r\n    \/*  http:\/\/developer.linkedin.com\/apis *\/\r\n\r\n    print (''.$user-&gt;id.'');\r\n    echo ('&lt;br&gt;');\r\n\r\n    print (''.$user-&gt;firstName.'');\r\n    echo ('&lt;br&gt;');\r\n\r\n    print (''.$user-&gt;lastName.'');\r\n    echo ('&lt;br&gt;');\r\n\r\n    print (''.$user-&gt;headline.'');\r\n    echo ('&lt;br&gt;');\r\n\r\n    \/*\r\n    print (''.$user-&gt;picture-url.'');\r\n    echo ('&lt;br&gt;');\r\n    *\/\r\n    print (''.$user-&gt;industry.'');\r\n    echo ('&lt;br&gt;');\r\n\r\n\r\n    \/\/ print &quot;Hello $user-&gt;firstName $user-&gt;lastName.&quot;;\r\n\r\n    exit;\r\n\r\n    function getAuthorizationCode() {\r\n        $params = array('response_type' =&gt; 'code',\r\n                        'client_id' =&gt; API_KEY,\r\n                        'scope' =&gt; SCOPE,\r\n                        'state' =&gt; uniqid('', true), \/\/ unique long string\r\n                        'redirect_uri' =&gt; REDIRECT_URI,\r\n                  );\r\n\r\n        \/\/ Authentication request\r\n        $url = 'https:\/\/www.linkedin.com\/uas\/oauth2\/authorization?' . http_build_query($params);\r\n\r\n        \/\/ Needed to identify request when it returns to us\r\n        $_SESSION['state'] = $params['state'];\r\n\r\n        \/\/ Redirect user to authenticate\r\n        header(&quot;Location: $url&quot;);\r\n        exit;\r\n    }\r\n\r\n    function getAccessToken() {\r\n        $params = array('grant_type' =&gt; 'authorization_code',\r\n                        'client_id' =&gt; API_KEY,\r\n                        'client_secret' =&gt; API_SECRET,\r\n                        'code' =&gt; $_GET['code'],\r\n                        'redirect_uri' =&gt; REDIRECT_URI,\r\n                  );\r\n\r\n        \/\/ Access Token request\r\n        \/\/ \r\n        $url = 'https:\/\/www.linkedin.com\/uas\/oauth2\/accessToken?' . http_build_query($params);\r\n\r\n        \/\/ Tell streams to make a POST request\r\n        $context = stream_context_create(\r\n                        array('http' =&gt; \r\n                            array('method' =&gt; 'POST',\r\n                            )\r\n                        )\r\n                    );\r\n\r\n        \/\/ Retrieve access token information\r\n        $response = file_get_contents($url, false, $context);\r\n\r\n        \/\/ Native PHP object, please\r\n        $token = json_decode($response);\r\n\r\n        \/\/ Store access token and expiration time\r\n        $_SESSION['access_token'] = $token-&gt;access_token; \/\/ guard this! \r\n        $_SESSION['expires_in']   = $token-&gt;expires_in; \/\/ relative time (in seconds)\r\n        $_SESSION['expires_at']   = time() + $_SESSION['expires_in']; \/\/ absolute time\r\n\r\n        return true;\r\n    }\r\n\r\n    function fetch($method, $resource, $body = '') {\r\n        $params = array('oauth2_access_token' =&gt; $_SESSION['access_token'],\r\n                        'format' =&gt; 'json',\r\n                  );\r\n\r\n        \/\/ Need to use HTTPS\r\n        $url = 'https:\/\/api.linkedin.com' . $resource . '?' . http_build_query($params);\r\n\r\n        \/\/ print_r($url);\r\n        \/\/ Tell streams to make a (GET, POST, PUT, or DELETE) request\r\n        $context = stream_context_create(\r\n                        array('http' =&gt; \r\n                            array('method' =&gt; $method,\r\n                            )\r\n                        )\r\n                    );\r\n\r\n\r\n        \/\/ Hocus Pocus\r\n        $response = file_get_contents($url, false, $context);\r\n\r\n        \/\/ Native PHP object, please\r\n        return json_decode($response);\r\n    }\r\n    ?&gt;\r\n\t \r\n\t<\/pre>\n<h2>En savoir plus<\/h2>\n<ul>\n<li>simple-linkedinphp, a PHP-based wrapper for the LinkedIn API<br \/><a href=\"https:\/\/code.google.com\/p\/simple-linkedinphp\/wiki\/QuickStart\" target=\"_blank\">https:\/\/code.google.com\/p\/simple-linkedinphp\/wiki\/QuickStart<\/a><\/li>\n<li>mahmudahsan \/ Linkedin&#8212;Simple-integration-for-your-website<br \/><a href=\"https:\/\/github.com\/mahmudahsan\/Linkedin---Simple-integration-for-your-website\" target=\"_blank\">https:\/\/github.com\/mahmudahsan\/Linkedin&#8212;Simple-integration-for-your-website<\/a><\/li>\n<li>petewarden \/ linkedinoauthexample<br \/><a href=\"https:\/\/github.com\/petewarden\/linkedinoauthexample\" target=\"_blank\">https:\/\/github.com\/petewarden\/linkedinoauthexample<\/a><\/li>\n<li>LinkedIn Developer Network &#8211; Getting an OAuth Token in PHP<br \/><a href=\"http:\/\/developer.linkedin.com\/documents\/getting-oauth-token-php\" target=\"_blank\">http:\/\/developer.linkedin.com\/documents\/getting-oauth-token-php<\/a><\/li>\n<li>LinkedIn Developer Network &#8211; Authentication<br \/><a href=\"http:\/\/developer.linkedin.com\/documents\/authentication\" target=\"_blank\">http:\/\/developer.linkedin.com\/documents\/authentication<\/a><\/li>\n<li>LinkedIn Developer Network &#8211; Share API<br \/><a href=\"https:\/\/developer.linkedin.com\/documents\/share-api\" target=\"_blank\">https:\/\/developer.linkedin.com\/documents\/share-api<\/a><\/li>\n<li>LinkedIn Developer Network &#8211; OAuth Test Console<br \/><a href=\"http:\/\/developer.linkedin.com\/oauth-test-console\" target=\"_blank\">http:\/\/developer.linkedin.com\/oauth-test-console<\/a><\/li>\n<li>Integrate linkedin api in your site<br \/><a href=\"http:\/\/thinkdiff.net\/linkedin\/integrate-linkedin-api-in-your-site\/\" target=\"_blank\">http:\/\/thinkdiff.net\/linkedin\/integrate-linkedin-api-in-your-site\/<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Il y avait au d\u00e9part de cet article, la volont\u00e9 de pouvoir partager correctement des articles sur Linkedin donc d&#8217;impl\u00e9menter le protocole Open Graph, le&hellip; <\/p>\n<p class=\"text-center\"><a href=\"https:\/\/flaven.fr\/2013\/11\/linkedin-api-oauth-se-connecter-et-rapatrier-des-informations-de-la-plate-forme-linkedin\/\" class=\"more-link\">Continue reading &rarr; <span class=\"screen-reader-text\">Linkedin, API, OAuth &#8211; Se connecter et rapatrier des informations de la plate-forme Linkedin<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":10112,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"bf_ai_meta_description":"Se connecter \u00e0 LinkedIn via API et OAuth pour rapatrier des informations. Utilisez des outils sp\u00e9cifiques pour des r\u00e9sultats pr\u00e9cis.","bf_ai_og_title":"Linkedin API, OAuth \u2013 Se connecter","footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[3439,3444,3445,3446,3448,3449,3435,3452],"tags":[2183,1939,54,1895,20],"class_list":["post-10104","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-apis-integration","category-programming-databases","category-seo-web-marketing","category-social-media-community","category-tools-productivity","category-tutorials-how-to","category-web-development","category-wordpress-cms","tag-api","tag-connexion","tag-linkedin","tag-oauth","tag-php"],"jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p3Vuhl-2CY","jetpack_featured_media_url":"https:\/\/flaven.fr\/wp-content\/uploads\/2013\/11\/og_for_linkedin_bf.jpg","_links":{"self":[{"href":"https:\/\/flaven.fr\/happy-api\/wp\/v2\/posts\/10104","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/flaven.fr\/happy-api\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/flaven.fr\/happy-api\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/flaven.fr\/happy-api\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/flaven.fr\/happy-api\/wp\/v2\/comments?post=10104"}],"version-history":[{"count":3,"href":"https:\/\/flaven.fr\/happy-api\/wp\/v2\/posts\/10104\/revisions"}],"predecessor-version":[{"id":10124,"href":"https:\/\/flaven.fr\/happy-api\/wp\/v2\/posts\/10104\/revisions\/10124"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/flaven.fr\/happy-api\/wp\/v2\/media\/10112"}],"wp:attachment":[{"href":"https:\/\/flaven.fr\/happy-api\/wp\/v2\/media?parent=10104"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/flaven.fr\/happy-api\/wp\/v2\/categories?post=10104"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/flaven.fr\/happy-api\/wp\/v2\/tags?post=10104"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}