Gowalla API Class (php)

// April 14th, 2010 // Cuvedev, Development, api, gowalla, php

I just quickly made a class for accessing the Gowalla API because I needed it myself. I looked for an existing class on the internet but could only find some crappy stuff on Google Code.
So I decided to make one myself.

The use of the class is fairly simple. Include the class file (don’t forget to add you API-key), make an instance and do your calls.
The class internally uses CURL to do the requests to the server and returns the data as an associative array.
I tried to document the methods enough so it’s easy to use them.

Example:

<!--?php
include('./class.gowalla.php');
$gowalla = new GowallaAPI();
$events	 = $gowalla--->getSpotEvents(846403);
foreach ($events['activity'] as $event)
{ // do stuff }
?&gt;

Feel free to download and comment.

11 Responses to “Gowalla API Class (php)”

  1. Patrick says:

    If the foreach loop, could you use: “echo $event->$activity_url;” to get the url?

  2. Klaas Cuvelier says:

    I suppose that would be:

    echo $event['activity_url'];

    Because I make an associative array from the json data, not an object. If you’d rather have an object instead of an array, remove the “true” parameter from json_decode and use:

    echo $event->activity_url;

    note, without the dollar sign in before activity_url

  3. snorpey says:

    Hi.
    Could you add a few more examples how to use this class?
    The example code you posted above doesn’t seem to work properly on my server (even though I added my API key)…
    Thanks!

  4. Klaas Cuvelier says:

    This is the code I used to test all my methods:
    http://www.cuvedev.net/wp-content/uploads/2010/05/gowalla.php.txt

    It’s pretty dirty looping and doing trial-error with the arguments, but this was the fastest to test my methods. So I’m sure my methods work.

    Another example:
    http://www.cuvedev.net/wp-content/uploads/2010/05/gowalla_example.php.txt

    I hope this helps you out.
    If you keep having problems, just let me know.

  5. snorpey says:

    thanks a lot for responding so quickly and providing more examples.

    i tried to implement the api class here: http://www.fishnation.de/bachelor/location-api/ajax/get-gowalla.php

    As soon as i create a new instance of the API class the script keeps seems to have connection problems (the script works fine before instantiating the API class). Right now, the code looks like this:

    Are there further requirements for the script to work? (the PHP version on my server is 5.2)

  6. Klaas Cuvelier says:

    And a requirement for the script is CURL, but that’s most of the time installed by default.
    Do you have error_reporting and display_errors on? So we can be sure there’s no error …

  7. snorpey says:

    Thanks again for helping me here…
    according to http://fishnation.de/info.php

    error_reporting = 6135 (E_ALL & ~E_NOTICE), display_errors = on, CURL is installed & enabled

    Do I have to make any changes to the class other than pasting in my API key?

  8. Klaas Cuvelier says:

    Weird that seems normal. It should work with only changing the apikey.
    You could send me your code (only relevant files) and I could take a look at it if you want.
    (I’m also intrigued why it doesn’t work for you)

  9. phebs says:

    Nice job! but somehow i get an Internal Server Error whnhe trying to download the zip, idk maybe ur hosting is having an issue right now? Thanks in advanced.

  10. Klaas Cuvelier says:

    @phebs, thx. Link should be working now.
    Good luck!

Leave a Reply