/ Published in: PHP
                    
                                        
Following our recent work on an [API for Cloudworks](http://freear.org.uk/node/40) I thought I\'d post this simple demo, which uses cURL and json_decode. [Email us](mailto:cloudworks AT open.ac.uk?subject=API) for an API key.  (15-24 June 2010.)
                
                            
                                Expand |
                                Embed | Plain Text
                            
                        
                        Copy this code and paste it in your HTML
<?php
/** A simple demonstration of the Cloudworks API, using cURL.
* @copyright 2010 The Open University.
*/
# Uncomment the following line to set a proxy for cURL.
//putenv("http_proxy=MY_HOST:PORT");
# Please request your API key via [cloudworks AT open.ac.uk]
$api_key = 'NNNNN'; //// MODIFY placeholder.
# Specify the item that you want.
$item_type= 'clouds'; # Or 'cloudscapes' etc.
$term = '2978'; # A cloud ID.
$related = null; # null: just view the cloud; or 'followers' etc.
# Form the request URL.
if ($related) $related = "/$related";
$url = "http://cloudworks.ac.uk/api/$item_type/$term$related.json?api_key=$api_key";
?><!DOCTYPE html><html lang="en"><meta charset="utf-8"><title>Cloudworks API Demo</title><?php #HTML5.
# Make the HTTP request.
echo "GET $url<br>";
$result= http_request_curl($url);
if ($result->success) {
# Success: display some data relevant to your request.
echo "OK: <a href='$item->html_url'>$item->title</a>";
} else {
# Handle HTTP errors.
echo ($item) ? "Error: $item->code, $item->message" : "Error: ".$result->info['http_code'];
}
?></html><?php
/** Make a HTTP request using cURL.
*/
function http_request_curl($url) {
}
$result->success = ($result->info['http_code'] < 300);
return $result;
}
Comments
 Subscribe to comments
                    Subscribe to comments
                
                