Ollie Hind
Ollie Hind

Reputation: 13

How do I parse the results from a Foursquare API call in PHP?

so my problem is I'm calling the Foursquare API with this GET request:

https://api.foursquare.com/v2/venues/4b522afaf964a5200b6d27e3?client_id=".$client_id."&client_secret=".$client_secret

And I don't know how to parse the results to display what I need. Typing it into the browser with client ID and client secret gives a page of correct results so I know the URL is correct. The problem is in this part of my code:

$json = json_decode($response);
        foreach ($json->response->venue as $result)
        {
            echo $result->name.' - '.$result->location->address.' '.$result->location->city."<p />";
        }

Here $response is the result from the GET request which I am trying to parse as JSON and display the name, address and city variables. Does anyone know my problem? Maybe the result returned isn't JSON or I'm structuring my parse wrongly? Any help would be very gratefully received. Thanks!

Upvotes: 0

Views: 1545

Answers (1)

Yi Yang
Yi Yang

Reputation: 13

you need to pass a "v=20120319" parameter in you call to the endpoint, otherwise the server will fail to know when you wrote the code and translate that to a certain API version it will use.

https://developer.foursquare.com/overview/versioning

Upvotes: 1

Related Questions