Archive

Posts Tagged ‘API’

SmartShanghai.com now using LiURL

April 21st, 2009

SmartShanghai.com is now using LiURL.cn to generate small url’s for all their twitter links.

frank

Its not immediately obvious, but if you click on the Twitter link (example below), you’ll see LiURL in use.

twitter

We worked with SmartShanghai in order to assist them with integration. SmartShanghai’s original plan was to run a script to generate url’s for all 5000+ venues. While this would have worked, it wasn’t an optimal solution for either site.

Our revised design works something like this.

On page load, SmartShanghai checks to see if they have a small url for the page in their database.
If they don’t, they call LiURL’s API (http://liurl.cn/api-create.php?url=[YOURURL]) to generate a Little URL, and save the URL locally in their database.

Simple, and elegant. URL’s are generated only once, on a page request by a user.

If you would like to use LiURL.cn in your site, let us know, and we can assist with integration.

For the technically inclined, sample PHP code to use LiURL.cn is below.

<?php

//Use cUrl to retrieve content
function get_content($url) {
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_HEADER, 0);
ob_start();
curl_exec ($ch);
curl_close ($ch);
$string = ob_get_contents();
ob_end_clean();
return $string;
}

//URL = url to encode
$url="http://www.example.com";

//Call the LiURL api
$content = get_content ("http://liurl.cn/api-create.php?url=". $url);

//Show our short url
echo $content;

?>
 

admin API, Site Related , , , ,

API Stuff / 短连接API

March 1st, 2009

We actually have an API for the LiURL site, although I haven’t really documented it that well as of yet.  As we’re a brand new site, we’re busy building in functionality, so this will get expanded in further posts as we add features.

To get a Shortened URL (aka Little URL) , the call is this:

http://liurl.cn/api-create.php?url=

Which returns the short URL. If you’ve been naughty and haven’t passed a valid URL, then it will return you a big fat -1 for your efforts.

Strangely enough, we also have the diametrically opposite call of that, which (suprise suprise)  gives you a long URL from a shortened one

http://liurl.cn/api-create.php?tinyurl=

This also returns a -1 failure if the URL isn’t one we know about.

Some sample PHP code after the break

虽然我目前仍未正式书面记录,不过在LiURL网站 我们已经使用了API。由于我们是新建的品牌网站,目前我们正忙于建设网站的功能性。所以这部分我们将在以后增加网站新特性时候加以扩充。

如果需要缩短后的链接 如下所示

http://liurl.cn/api-create.php?url=

它将返回缩短后的链接。如果您没有通过正规的链接那么将会出现大大的 -1错误提示。

奇怪的是,我们也遇到了完全相反的情况,有时它会从短链接提供一个长链接(非常奇怪)。

http://liurl.cn/api-create.php?tinyurl=

如果链接不正确 它同样也会出现 -1 错误提示。

以下是一些错误后的PHP编码样本。

Read more…

admin API , , ,