If you are seeing this message, our style sheet has failed to load. Please try each of the following steps, in order, to fix it:

1) Clear your browser's cache and refresh the page.

2) Wait a few minutes, clear the cache again and refresh (one of our CDN servers may have had a short temporary outage).

3) Try accessing our site from another web browser on the same computer, AND from another computer on the same network. If either of those fixes it, you likely have software such as ad-block or Ghostery installed on the affected browser/computer. Please disable those to see if that fixes the issue.

4) Open a terminal window and type "ping cdn.staticstuff.net". Send us an email with the result.



Forums » Developers



Starting out with the API

Hi there

I would like to create a single page (php) that displays certain information (which looks possible according to the api documentation).

However, I'm a bit of a n00b with this...so I wanted to know is where do I start with it?

I looked at the examples but I still couldn't figure it out :(

Thanks!

Posted Sat May 31 2008 8:23am by shaan_l


PHP's file() function can read data both on the local server, but also remotely if you give it a URL. So you could do like this:

$result = file( "http://api.getclicky.com/..." );

Then $result will have the output from the API. Since you are using PHP, you'll want to specify the output as PHP, which will make the data real easy work with. For example, this. Then you run those results through unserialize(), which will transform it into an array.

$result = unserialize( $result );

Then you can use the "foreach" construct to loop through the array and print out the results. To see what the array is structured like, you can do this, which will help you decide how to work with it:

print_r( $result );

Posted Sat May 31 2008 2:01pm by Your Friendly Clicky Admin


You are probably better off using file_get_contents() instead of file() so that your output is returned in a string rather than an array.

Otherwise, if you use file() the above unserialize() will not work. You would have to do unserialize($result[0]) or flatten the array using any of the many methods available to do so.

Long story short, just use file_get_contents(). :)

Also, if you run into problems getting either of these file* functions to work, you may want to check your phpinfo() to be sure that allow_url_fopen is set to On which is what allows these functions to accept a URL as the filename. Chances are it is by default but just something to be aware of that might save some of you hours of headache trying to figure out what is wrong.

Hope this helps.

Posted Sun Jul 13 2008 11:26am by synapsestudios


You're right, in this case FGC should be used.

Posted Mon Jul 14 2008 11:38am by Your Friendly Clicky Admin


"Then you can use the "foreach" construct to loop through the array and print out the results."

Could someone please give me an example of how to do this? Thanks in advance for your help.

Posted Sun Jan 3 2010 8:21pm by jshungat


I still cannot figure out how to print data - I am a total newb here! How can I print out the info from this api url: http://api.getclicky.com/api/stats/4?site_id=xxxxxx&sitekey=xxxxxxxx&type=visitors&date=last-30-days

?

inputting this:
$result = file_get_contents( "same url" );
print_r( $result );

just causes a weird array to print (i put the same url above but cannot put more than one URL in this post it appears). I just want the one darn number! LOL

thanks for any help you can give!

Posted Thu Sep 23 2010 10:38pm by kmedhus


http://php.net/foreach

Posted Thu Sep 23 2010 10:48pm by ameer_david-DELETED


Well first you need to specify PHP output. Here's what it would look like:

$result = file_get_contents("http://api.getclicky.com/api/stats/4?site_id=xxxxxx&sitekey=xxxxxxxx&type=visitors&date=last-30-days&output=php");
foreach( $result['visitors'] as $date => $more ) {
  $visitors = $more[0];
}

Then $visitors should have the value. Although foreach() is a loop, there's only one item in the array, but you don't know what the array "key" is, so you have to use foreach to get inside the data without knowing the key.

Posted Fri Sep 24 2010 10:25am by Your Friendly Clicky Admin


I am trying to figure this out want to put in use on my site http://greensboro-nc.com apis scare me because of my lack of knowledge. I need to learn more. Will give it a whirl
Thanks

Posted Thu Nov 18 2010 1:10pm by roosteri



Reply to this discussion

You must be logged in to your account to post!