Dear fellas,

I've been reading and trying to change to the new Twitter API for like three weeks now.. I gotta tell you, it is really confusing on how to use it..

I was running a website (search tweets using GeoLocation, Longitude and Latitude);

I've been trying to fix it with the new API but I'm failing!

If someone can help in this, will be appreciated, and he'll be credited in the source code.

Here is the old (was working) code of the search:



 * Description: Fetch tweets from within a certain radius of a certain location defined by 
 *              longitude and latitude and provide a link back to them.
 * Parameters:  
 *   $long: Longitude (e.g. '40.757929')
 *   $lat: Latitude (e.g. '-73.985506')
 *   $radius: Distance (e.g '25km')
 *   $numberOfTweets: Number of tweets to display (e.g. 2)

function getGeoTwitterFeed($long, $lat, $radius, $numberOfTweets ) {

    //spacer - do not change
    $sp = '%2C';

    //generate rss link
    $link = 'http://search.twitter.com/search.rss?geocode=' . $lat . $sp . $long . $sp . $radius;

    //load the feed into an xml element
    $current_xml = new SimpleXMLElement($link, null, true);

    //begin output as unordered list
    //print '';

    //count how many tweets have been output
    $count = 0;

    //print out each twitter link
    foreach($current_xml->channel->item as $item) {

        //remove all php and html tags
        $item->title = strip_tags($item->title);
        $item->pubdate = strip_tags($item->pubDate);
        $google = $item->children("http://base.google.com/ns/1.0"); 
        $profileimg = $google->{"image_link"};
        $normalimg = str_replace("_normal","_reasonably_small",$profileimg);

        //check limit of tweets to output
        if($count <= $numberOfTweets) {

            //output link
            print '<section class="cf"><a href="'.$item->link.'" target="_blank"><img alt="" src="'.$normalimg.'"><p>'.$item->title.'<span></span><b>'.$item->pubdate.'</b></p></a></section>' ;

            //increment counter for number of tweets output


    //end unordered list
    //print '';



 require_once 'twitter.php';
 $long = $_GET["long"];
 $lat = $_GET["lat"]; 
 $radius = $_GET["rad"]; 
 $numberOfTweets = $_GET["num"]-1;
 getGeoTwitterFeed($long, $lat, $radius, $numberOfTweets );

Thanks in advance :)

Edited by Q8iEnG

5 Years
Discussion Span
Last Post by cereal


late reply, but it can still be useful for people searching. At line 19 you wrote:

$link = 'http://search.twitter.com/search.rss?geocode=' . $lat . $sp . $long . $sp . $radius;

which it may be valid in API 1.0, but in Twitter API 1.1 the link changes to:

$link = "https://api.twitter.com/1.1/search/tweets.json?geocode=$lat,$long,$radius&q=pizza";

The q parameter is required, so it cannot be omitted. Also you have to append mi (mile) or km (kilometer) to the radius variable.

More information: https://dev.twitter.com/docs/api/1.1/get/search/tweets

Edited by cereal

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.