Created
July 2, 2013 23:33
-
-
Save planetoftheweb/5914179 to your computer and use it in GitHub Desktop.
This gist will let you retrieve a series of tweets using the twitter v1.1 API. There's a few steps you have to do before you use this. 1. First, you need to go to http://dev.twitter.com/apps and create a new application. 2. You'll also need to download this library. https://github.com/themattharris/tmhOAuth (You only need the tmhOAuth.php file)
…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require 'tmhOAuth.php'; // Get it from: https://github.com/themattharris/tmhOAuth | |
// Use the data from http://dev.twitter.com/apps to fill out this info | |
// notice the slight name difference in the last two items) | |
$connection = new tmhOAuth(array( | |
'consumer_key' => '', | |
'consumer_secret' => '', | |
'user_token' => '', //access token | |
'user_secret' => '' //access token secret | |
)); | |
// set up parameters to pass | |
$parameters = array(); | |
if ($_GET['count']) { | |
$parameters['count'] = strip_tags($_GET['count']); | |
} | |
if ($_GET['screen_name']) { | |
$parameters['screen_name'] = strip_tags($_GET['screen_name']); | |
} | |
if ($_GET['twitter_path']) { $twitter_path = $_GET['twitter_path']; } else { | |
$twitter_path = '1.1/statuses/user_timeline.json'; | |
} | |
$http_code = $connection->request('GET', $connection->url($twitter_path), $parameters ); | |
if ($http_code === 200) { // if everything's good | |
$response = strip_tags($connection->response['response']); | |
if ($_GET['callback']) { // if we ask for a jsonp callback function | |
echo $_GET['callback'],'(', $response,');'; | |
} else { | |
echo $response; | |
} | |
} else { | |
echo "Error ID: ",$http_code, "<br>\n"; | |
echo "Error: ",$connection->response['error'], "<br>\n"; | |
} | |
// You may have to download and copy http://curl.haxx.se/ca/cacert.pem |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is it possible to get tweet fav(likes) and retweets count.