How to get image url from tweets using search.twitter?


Hey, I’ve got a twitter website which searches for results which use the phrase ‘FloorPic’. One of the things I want to do is that if the tweet has an image, I want to display it on my website, not have a link to it. Using search.twitter API is there anyway to get the source URL of a tweeted image with the format ATOM

Here is my code if it is of relevance:

// get the keyword from url
$srchterm = $_GET["q"];
// encode it for the safe search
$srchterm = urlencode($srchterm);
// search the keyword using Twitter API
//$srch_twitts = "";
$srch_twitts = "".$srchterm."&rpp=100&include_entities=true";
// use curl to execute the Twitter URL
$twits = curl_init();
curl_setopt($twits, CURLOPT_URL, $srch_twitts);
curl_setopt($twits, CURLOPT_RETURNTRANSFER, TRUE);
$twi = curl_exec($twits);
// here we have the searched result in an array
$search_res = new SimpleXMLElement($twi);
/* display the data */
$i = 0;
// displays the search keyword
echo "<p style='padding-left:10px; color:brown'>Your search term is: " . $srchterm . "</p>";
// tweets in an array. split it by foreach
// we need only 10 result so, use if condition
foreach ($search_res->entry as $result) if ($i++ < 100)
if (strpos($result->content,'') !== false) {
echo "<div id='tweets' class='image'>";
else {
echo "<div id='tweets' class='noimage'>";
echo "<div class='avatar'><img src='". $result->link[1]->attributes()->href. "' /> </div>";
echo "<div class='twitcont'>";
echo "<div class='name'>". $result->author->name . "</div>";
echo "<div class='content'>" . $result->content ;
if (strpos($result->content,'') !== false) {
    $position = mb_strpos($result->content,'');
    $url = substr($result->content, -26, -4);
    echo "Expanded URL:".$result->entities->urls->expanded_url;
    echo 'This contains a picture at position '.$position;

As you can see towards the end, I have managed to be able to find what is a link so I know what tweets have links and which ones don’t.


Also, To see what I am talking about here is my website:-

The light colored tweets have an image, the dark ones do not.


This question is probably more complicated than you think it is – you’re using a deprecated version of the API (the API and the ATOM format are both permanently retiring in June 2013). Take a look at the modern Search API which has a a better, more detailed response format: [node:10287]