Created
March 7, 2012 05:27
-
-
Save vinaydotblog/1991261 to your computer and use it in GitHub Desktop.
php: Fetch public user tweets
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 | |
// 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