![]() |
|
|
Developing for the yURLo.com APIThe yURLo.com website provides an API for developers to incorporate the yURLo URL shortening functionality into their own applications. How to use the APIIn order to use the yURLo API, you must first request an API key, which is a unique key that works similar to a password, allowing you access to the API functionality. Once you have obtained an API key, you may begin using the API immediately. IMPORTANT! If you're developing an application or plugin that will be distributed to other people/users, you MUST provide a mechanism for them to enter their own API key. Distribution of your API key (even if it's a compiled or encrypted application) is strictly forbidden and doing so will result in your key being disabled, rendering the yURLo.com functionality in your application useless. The base URL of the API is http://yurlo.com/api.php. The API accepts two parameters: guid and url. The guid parameter should contain your API key, and the url parameter should contain the URL you wish to create a yURLo for, properly "URL Encoded". If you're unfamiliar with URL encoding, see this page for more information. Requests are made via HTTP using either the GET or POST request method. The following is an example API call using the GET method: http://yurlo.com/api.php?guid=601ba83045aa710ca38f8221757b110a&url=http%3A%2F%2Fwww.google.com%2Fsearch%3Fq%3Dshoes The example is requesting a yURLo for the URL http://www.google.com/search?q=shoes. Results are returned in XML format. The resulting XML for our example above would be: <?xml version="1.0"?>
<link> <status>OK</status> <url>http://www.google.com/search?q=shoes</url> <yurlo>http://yurlo.com/ig2hbh</yurlo> </link> There are up to three elements nested inside the <link> element. Their descriptions and possible values are as follows.
The following is a basic example using the SimpleXML functionality available in PHP 5. The text "MYAPIKEY" would be replaced with your API key, or if your application is to be distributed to other people, the API key of the user of the application. $url = 'http://www.google.com/search?q=shoes';
$encoded_url = urlencode($url); $api_url = "http://yurlo.com/api.php?guid=MYAPIKEY&url=$encoded_url"; $yurlo_xml = file_get_contents($api_url); $xml = simplexml_load_string($yurlo_xml); if(!$xml) { echo "SimpleXML object creation failed!"; exit; } if($xml->status != 'OK') { echo "There was something wrong!"; exit; } echo "The new yURLo is: " . $xml->yurlo; |