yURLo.com - Make a long URL short!



Developing for the yURLo.com API

The yURLo.com website provides an API for developers to incorporate the yURLo URL shortening functionality into their own applications.

How to use the API

In 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.

  • <status>
    The status element is always present and contains one of five possible responses:
    • OK - The request was successful and the yURLo was created.
    • BADGUID - The API key was not supplied or was invalid.
    • BADURL - The URL is known to be related to or used in spam.
    • INVALID - The URL given was invalid.
    • ERROR - There was an internal error and the request could not be completed.
  • <url>
    This is the original URL submitted. This element will only exist if the status is OK.
  • <yurlo>
    This is the new, shorter link (or yURLo). This element will only exist if the status is OK.

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;
Copyright © 2010 Steve Thomas. All Rights Reserved.