Search code examples
phpapiyelp

How to get results using yelp api


Sorry, this might be pretty basic. I'm trying to use the Yelp API and am running a test search for McDonalds in Baltimore.

this is the code:

<?php

    $AccountKey = "XXXX";
    $restaurant = "McDonalds";
    $city = "Baltimore";

    $file = "test.txt";

    $data = http_get("http://api.yelp.com/business_review_search?term=".$restaurant."&location=".$city."&ywsid=".$AccountKey);

    file_put_contents($file, $data);

 ?>

I'm trying to store the results in test.txt which I can then parse but its not working. Any ideas?

Thanks in advance!


Solution

  • In your code you didn't open the text file.

    // Open the file to get existing content
    $data = file_get_contents($file);
    $data. = http_get("http://api.yelp.com/business_review_search?term=".$restaurant."&location=".$city."&ywsid=".$AccountKey);
    // Write the contents back to the file
    file_put_contents($file, $data);
    

    more details