Hello coders! I’m so exited about the introduction of the API that I needed to share my personal code that I use to test this new feature.
This example code will get the non-experienced coders started in testing and playing with the new API . It uses JSON instead of the more logical XML only because it’s more fun to play with when you want speed and not elegance (I might do this again in XML some time).
I got the example username and api-key from the introduction post (http://themeforest.net/forums/thread/a-brief-introduction-to-the-api/10945)
I used json_decode (PHP 5 >= 5.2.0, PECL json >= 1.2.0)
Colored version of the code: http://lygon.net/themeforest.phps
<?php <br?>$api = “http://marketplace.envato.com/api/”; // Url of the actual API
$version = “edge”; // Edge is the development version, releses will be numbers
$username = “ryan”; // Your username
$apikey = “26k6otse2s586e4hcbzjy3quq830t3o4”; // Your api key
$sets = “vitals+recent-sales”; // sets you want to get. Format: set+otherset+etc
$url = ”$api$version/$username/$apikey/$sets.json”;
$rawdata = file_get_contents($url); // We get the contents, if you have remote locations disabled in your php.ini, you can use curl or something else here to get the actual HTTP data
$data = json_decode($rawdata, true); // Sets $data variable as the decoded json file in array
// Up to you (I’m assuming you know what to do with the array)
print_r($data); // This example just outputs the data, could be usefull for debugging
That is brilliant!
May I suggest using http://pastie.caboo.se for code samples? That way we probably wont have any problem with our forums bonking up the code
Also, if anyone is doing a JS or AS example, remember you can just get the JSON response and go
data = eval(response) and then access it like
- Please read our community guidelines. Self promotion and discussion of piracy is not allowed.
- Open a support ticket if you would like specific help with your account, deposits or purchases.
- Item Support by authors is optional and may vary. Please see the Support tab on each item page.
Most of all, enjoy your time here. Thank you for being a valued Envato community member.