Skip to content

Instantly share code, notes, and snippets.

@Bendihossan
Created April 13, 2013 16:06
Show Gist options
  • Save Bendihossan/5378980 to your computer and use it in GitHub Desktop.
Save Bendihossan/5378980 to your computer and use it in GitHub Desktop.
Get tweets from twitter in less than 20 lines of PHP.
<?php
define('CONSUMER_KEY', 'your-key');
define('CONSUMER_SECRET', 'your-key');
define('TWITTER_TOKEN', 'your-key');
define('TWITTER_TOKEN_SECRET', 'your-key');
$oauth = new OAuth(CONSUMER_KEY, CONSUMER_SECRET, OAUTH_SIG_METHOD_HMACSHA1, OAUTH_AUTH_TYPE_URI);
$oauth->setToken(TWITTER_TOKEN, TWITTER_TOKEN_SECRET);
$oauth->fetch('https://api.twitter.com/1.1/statuses/home_timeline.json?count=10');
$tweets = json_decode($oauth->getLastResponse(), true);
foreach ($tweets as $tweet) {
print $tweet['user']['screen_name']. ": \n";
print $tweet['text'];
print "\n\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment