Hello

I'm Manmohanjit Singh and this is my WordPress powered blog. I'm currently in Malaysia. I go to school at SMK USJ 12. I'm a quiet guy but I'm not shy. I'll talk only when I need to.

@twitter

Twitter

  • Loading...

@manmohanjit

Now Playing

  • Loading...

manmohanjit1

# Using TinyURL's API to create short URL's automatically

by Manmohanjit Singh on Feb 19th, 2010 in Web Programming.

Recently I’ve been playing around with Twitter’s API, when I make a post a tweet will automatically be made on my Twitter account. I’ll get on that later. I like bit.ly, it provides short URLs in no time but its API isn’t the easiest to work with. So tinyurl.com has a long but easy to use API, I had no other choice to shorten my URLs with TinyURL, anyway something is better than nothing. Its actually pretty simple to shorten URLs with TinyURL.

Lets say we are creating a function, getTinyURL(). You can edit it to match your needs later.

function getTinyURL($url) {
	$tinyurl = file_get_contents("http://tinyurl.com/api-create.php?url=".$url);
	return $tinyurl;
}

So you see, you just need to provide a URL, for a example: will return http://tinyurl.com/ylxlw6kr. The TinyURL provided is longer than my sites URL :| Anyway, it’ll work great for my posts which uses extremely long URLs.

Tags:

2 comments

  • By Steve

    73 days ago

    I’m wondering if there is a limit per/hour, per/day, etc.. of how many tiny urls you can generate with this? But how do they even track usage without requiring you to use your own assigned id – It’s hard to believe they don’t.

    Maybe they track it by I.P. address, if they do it all.

    • By manmohanjit

      72 days ago

      I don’t think there is :)

Leave A Comment

I'm watching you, please be nice and try not to spam. Comments are moderated. You can paste links directly, it will be formatted automatically. Basic XHTML tags are allowed.

Oh, I almost forgot. Comments are powered by Ajax, so don't hit the submit button twice. Thanks!

Wait for 15 seconds...