Created
February 22, 2011 20:30
-
-
Save dphiffer/839328 to your computer and use it in GitHub Desktop.
Last 100 Twitter mentions in CSV format
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 | |
// Twitter username | |
$user = 'MuseumModernArt'; | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL, "http://search.twitter.com/search.json?q=$user&result_type=recent&rpp=100"); | |
curl_setopt($ch, CURLOPT_HEADER, 0); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | |
$json = curl_exec($ch); | |
curl_close($ch); | |
header('Content-Disposition: attachment; filename="mentions.csv"'); | |
header("Content-Type: text/csv; charset=utf-8"); | |
$response = json_decode($json); | |
$out = fopen('php://output', 'w'); | |
foreach ($response->results as $tweet) { | |
fputcsv($out, array( | |
$tweet->created_at, | |
$tweet->from_user, | |
preg_replace('/\s+/', ' ', $tweet->text) | |
)); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment