Skip to content

Instantly share code, notes, and snippets.

@ptasker
Created March 14, 2013 20:24
Show Gist options
  • Select an option

  • Save ptasker/5164901 to your computer and use it in GitHub Desktop.

Select an option

Save ptasker/5164901 to your computer and use it in GitHub Desktop.
PHP Twitter Image grabber
<?php
if( isset($_GET['username']) ){
$user = mysql_real_escape_string( strip_tags( $_GET['username'] ));
$ext = '';
echo "<p>";
for( $i = 1; $i<100; $i++ ){
if( $i>1 ){
$ext = "&username=".$user;
}
echo '<a href="?page='.$i.$ext.'">'.$i."</a>&nbsp;|&nbsp; ";
}
echo "</p>";
$page = isset($_GET['page'] ) ? (int) $_GET['page'] : 1;
$file = "https://api.twitter.com/1/statuses/user_timeline.json?include_entities=true&include_rts=true&screen_name=".$user."&count=200&page=".$page;
$tweets = json_decode(file_get_contents($file));
if($tweets){
foreach($tweets as $tweet){
if(isset($tweet->entities->media)){
foreach($tweet->entities->media as $m){
//var_dump($m);
if($m->type=='photo'){
echo "<a href='".$m->media_url.":large'><img src='".$m->media_url.":thumb' /></a> &nbsp;";
}
}
}
}
}
}else{
?>
<form method="GET">
User: <input type="text" name="username" />
<input type="submit" value="Go" name="submit">
</form>
<?php } ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment