Skip to content

Instantly share code, notes, and snippets.

@vinaydotblog
Created March 7, 2012 05:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vinaydotblog/1991261 to your computer and use it in GitHub Desktop.
Save vinaydotblog/1991261 to your computer and use it in GitHub Desktop.
php: Fetch public user tweets
<?php
// Functions to fetch public tweets of any user
// Let's update this
function get_tweets($screen_name = 'vinnizworld'){
$api_url = "https://api.twitter.com/1/statuses/user_timeline.json";
$feed = $api_url."?screen_name=".$screen_name."&limit=20";
$headers = get_headers($feed);
$tweets = array();
if (!strpos($headers[0], '200')) {
return false;
}
else{
$a = json_decode(file_get_contents($feed));
foreach($a as $status){
$tweet['status'] = $status->text;
$tweet['posted_on'] = date("Y-m-d h:m:s",strtotime($status->created_at));
array_push($tweets,$tweet);
}
return $tweets;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment