Les OAuth settings
de votre application app-parse-list-widget
. Ces paramètres résument toutes les informations dont vous aurez besoin pour vous connecter via OAuth
à votre application Twitter. Bien évidemment, les clés données ci-dessous ne sont présentées qu’à titre d’exemple, notamment les permission d’accès.
Les paramètres OAuth de votre application Twitter
Il faut rendre public le widget de sorte que vous puissiez obtenir la possibilité de faire des requêtes. Pour se faire, il faut Cliquer sur Public lors de la création de votre application sur Twitter.
Les paramètres à compléter pour faire fonctionner l’Authentification OAuth
pour votre application Twitter
define('_TWITTER_USER_', 'bflaven'); define('_NB_TWEETS_', '1'); define('_CONSUMER_KEY_', 'IhivoXX896laQqT22CL7kQ'); define('_CONSUMER_SECRET_', 'AxvM7x2fK5Ppkly4XSGzJfuQUe3uC0VcY9VJvqPcA'); define('_ACCESS_TOKEN_', '32123456-PsLXOEvth8Ny0tSa2UsaZXe8o6D3DaG0s50pDecoL'); define('_ACCESS_TOKEN_SECRET_', 'Py7Sipi1Bs0bByakACjA3QF2AXo7fAtr7gx6qsP7R72'); define('_OAUTH_CALLBACK_', 'http://flaven.fr'); |
Une fois la procédure de création terminée, il reste à prendre le nom du widget.
Dans le code embed donné par Twitter, vous avez le nom de votre widget ex troiswdoc-hecube-list
<a class="twitter-timeline" href="https://twitter.com/bflaven/troiswdoc-hecube-list" data-widget-id="392871243596062720">Tweets from @bflaven/troiswdoc-hecube-list</a> <script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+"://platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script> |
Le fichier grab_tweets_from_widget_list_with_twitteroauth.php
, comme le nom du fichier l’indique ce fichier permet de récupérer les tweets d’un widget list créé sous Twitter
<?php session_start(); /* Path to twitteroauth library */ /* Put the OAuth.php and twitteroauth.php in the correct directory for /twitteroauth/ */ require_once("twitteroauth/twitteroauth.php"); /** * @file * A single location to store configuration. */ /* Replace by your own data */ define('_TWITTER_USER_', 'bflaven'); define('_NB_TWEETS_', '1'); define('_CONSUMER_KEY_', 'IhivoXX896laQqT22CL7kQ'); define('_CONSUMER_SECRET_', 'AxvM7x2fK5Ppkly4XSGzJfuQUe3uC0VcY9VJvqPcA'); define('_ACCESS_TOKEN_', '32123456-PsLXOEvth8Ny0tSa2UsaZXe8o6D3DaG0s50pDecoL'); define('_ACCESS_TOKEN_SECRET_', 'Py7Sipi1Bs0bByakACjA3QF2AXo7fAtr7gx6qsP7R72'); define('_OAUTH_CALLBACK_', 'http://flaven.fr'); /* Widget name */ /* Replace by your own widget */ define('_TWITTER_WIDGET_SLUG_', 'troiswdoc-hecube-list'); /* VALUES */ $twitteruser = ''._TWITTER_USER_.''; $notweets = ''._NB_TWEETS_.''; $consumerkey = ''._CONSUMER_KEY_.''; $consumersecret = ''._CONSUMER_SECRET_.''; $accesstoken = ''._ACCESS_TOKEN_.''; $accesstokensecret = ''._ACCESS_TOKEN_SECRET_.''; function getConnectionWithAccessToken($cons_key, $cons_secret, $oauth_token, $oauth_token_secret) { $connection = new TwitterOAuth($cons_key, $cons_secret, $oauth_token, $oauth_token_secret); return $connection; } $connection = getConnectionWithAccessToken($consumerkey, $consumersecret, $accesstoken, $accesstokensecret); /* Check out the widget */ /* Be sure to use the correct slug eg troiswdoc-hecube-list */ $tweets = $connection->get('https://api.twitter.com/1.1/lists/members.json?slug='._TWITTER_WIDGET_SLUG_.'&owner_screen_name='._TWITTER_USER_.''); /* FOR DEBUG ONLY */ // print_r($tweets); /* DECODE JSON */ $json = json_encode($tweets); $json = json_decode($json, true); /* Print out parsing the needed values sent back by the json of Twitter */ for ($i = 0; $i <= count($json); $i++) { $tweet = $json['users'][$i]["status"]["text"]; echo (''.$tweet.''); echo ('<br/>'); } ?> |