Search code examples
phpjsonapifoursquare

how to add links to a list of whats trending from the Foursquare API using PHP


Hi so I have created a list of the trending places in a given area using the Foursquare API: see the following link http://createmate.co/foursquare-whatshot/

I am trying to figure out how to make each item link to its respective Foursquare URL. Here is the code so far...

<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>Foursquare What's Hot</title>

    <!-- external CSS link -->
    <link rel="stylesheet" href="css/normalize.css">
    <link rel="stylesheet" href="css/style.css">
</head>

<body>
    <div id="container">

        <h1>Foursquare What's Hot</h1>
        <?php 

            /* GET THE DATA */

            $trending_url = file_get_contents("https://api.foursquare.com/v2/venues/trending?ll=40.7,-74&oauth_token=BQEPEMYIFHHH2C1OGBTJDI4GBYV5HQAPNFLR5ON1JIAI42GN&v=20130220");

            $trending_output = json_decode($trending_url);



            /* TEST THE DATA */

            //echo "<pre>";
            //print_r($trending_output);
            //echo "</pre>";


            /* PRINT RESULTS */
            for ($i=0;$i<10;$i++) { 
                echo "<ul id ='locations'>";  
                echo "<li> <a href= " . $trending_output->response->venues[$i]->canonicalURL . "> <h3>" . $trending_output->response->venues[$i]->name . "<br>";
                echo "<li> <h4>" . $trending_output->response->venues[$i]->location->address . "<br>";  
                echo "</ul>";  
            }



        ?>



    </div>
</body>

Any help is much appreciated.

Adam


Solution

  • The property you retrieve should be canonicalUrl, not canonicalURL.

    You should also surround your href attribute with quotes and don't forget to close your <a> tag as well.