Welcome!

My name is Manmohanjit Singh and I’m 15 this year. Sorry you’ll just have to accept it, I may be a kid to you but trust me I’m not. I live in Malaysia and I go to school at SMK USJ 12. Read more...

Twitter

  • Loading...

@manmohanjit

Recent Tracks

  • Loading...

manmohanjit1

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

by Manmohanjit Singh on Feb 19th, 2010 in Code.

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

    112 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

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