23 posts
  • Has been a member for 5-6 years
  • Exclusive Author
  • Referred between 1 and 9 users
  • Finland
  • Sold between 1 000 and 5 000 dollars
  • Bought between 1 and 9 items
Lahdekorpi says

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

?> $version 

578 posts
  • Attended a Community Meetup
  • Australia
  • Bought between 100 and 499 items
  • Contributed a Blog Post
  • Exclusive Author
  • Has been a member for 8-9 years
  • Referred between 1 and 9 users
+1 more
ryan says

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 :)

But thanks!

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 data['vitals']['balance'] !!!

105 posts
  • Author had a Free File of the Month
  • Beta Tester
  • Bought between 1 and 9 items
  • Exclusive Author
  • Has been a member for 5-6 years
  • Referred between 10 and 49 users
  • Sold between 1 000 and 5 000 dollars
Short says

Great :D

by
by
by
by
by
by