Shortening with YOURLS and Tweetie 2 for iPhone

by Brian Enigma on October 22, 2009 5:30pm

in Code,Projects,Twitter,iPhone

A few months back, around the pos­si­ble demise of the tr.im URL short­en­ing ser­vice, there was a sud­den rise in pop­u­lar­ity with run­ning your own URL short­ener on your own bou­tique URLThat was when I set up Ninja Me (nja.me) using YOURLS.  At the time, I reverse-engineered the undoc­u­mented API enough to hack Twitter-Tools to use that instead of bit.ly.  (As a side­bar, Twitter-Tools has since added offi­cial hooks for the URL pro­cess­ing, mak­ing my inel­e­gant hack just that: an inel­e­gant hack.  I need to write a real solu­tion soon.) The most recent ver­sion of YOURLS, 1.4, has fully doc­u­mented the API.  Serendip­i­tously, this comes at the same time that Tweetie 2 for the iPhone added cus­tom URL short­en­ing.

custom-urlshortening+yourls-sm=WIN!

You can then com­bine the power of Open Source with the power of well-documented closed-source and use your YOURLS instal­la­tion with Tweetie.  It is actu­ally quite simple.

Ver­sions

This post is specif­i­cally about the 1.4 ver­sion of YOURLS and the 2.0a ver­sion of Tweetie for the iPhone, but I assume should work (per­haps with minor mod­i­fi­ca­tion) for future ver­sions — try it and let me know the result! The browser screen­shots that fol­low are Fire­fox 3.5.  If you are using Safari, you will see much of the same text, but minus the for­mat­ting and sur­round­ing tags.  I have no idea what Inter­net Explorer will do, but I have pre­vi­ously seen it want to down­load XML as a file instead of dis­play­ing it.  If in doubt, just use Firefox.

Deter­min­ing Your Cus­tom URL

Before you can con­fig­ure Tweetie, you need to deter­mine what URL to give it.  If you feel con­fi­dent in your web skills, you can prob­a­bly jump to the end of this sec­tion for the final URL, oth­er­wise keep read­ing.  The spe­cific URL is highly depen­dent upon your YOURLS domain name, instal­la­tion loca­tion, and login.  It can be cal­cu­lated with a tiny amount of work, as you will see.

The cus­tom URL begins with the URL to where you have installed YOURLS.  For me, this is “http://nja.me”.  For you, it is another domain and may include a sub­di­rec­tory.  Take this, and append “yourls-api.php” to the URL.  To ver­ify, you can enter this URL in a web browser (for me, it is http://nja.me/yourls-api.php), and you should see some­thing to the effect of “Please Log In.”  This is the base URL to which you will add some para­me­ters: your username/password, action, and format.

please_log_in

Take that base URL and start by adding “?username=MyUsername&password=MyPassword”, of course replac­ing MyUser­name with your actual user­name and MyPass­word with your actual pass­word.  You set this up when you first installed YOURLS, but if you have for­got­ten, it can be found by open­ing includes/config.php in a text edi­tor and look­ing for the sec­tion $yourls_user_passwords.  (In my instal­la­tion, I have one username/password com­bi­na­tion I use inter­ac­tively and one I use for the Word­Press and Tweetie API, but I’m extra para­noid like that.) If you paste this new URL into a browser, you should get a mes­sage about a miss­ing action if every­thing went correctly.

missing_action

If you see this mes­sage, then just append “&action=shorturl&format=simple&url=%@” to your URL.  This will give you a final URL that looks some­thing like this (obvi­ously, with your own domain name, user­name, and password):

http://nja.me/yourls-api.php?username=MyUsername&password=MyPassword&action=shorturl&format=simple&url=%@

Try past­ing that in your browser, but man­u­ally replac­ing that funny “%@” with, for instance, http://google.com:

http://nja.me/yourls-api.php?username=MyUsername&password=MyPassword&action=shorturl&format=simple&url=http://google.com

This should print back a short URL that points to Google.  If this is the case, you’re good to go.

Con­fig­ur­ing Tweetie

  • Go to the top level “Accounts” screen in Tweetie.
  • Touch the “Set­tings” but­ton in the lower-left.
  • Touch the “URL Short­en­ing” option:

    select_custom

  • Touch the “Cus­tom…” option.
  • Enter the cus­tom URL you got from the above sec­tion.  This is the URL with “%@” in it.  Tweetie auto­mat­i­cally replaces that funny lit­tle two-character code with the URL to shorten.

    custom-urlshortening-entered

  • Touch the “Save” button.”

Test It

  • Get your­self a nice long URL.  I opened Mobile Safari, typed “test” into the search bar, then copied the nice long result­ing Google URL.
  • Start a new tweet and paste the URL in there.

    longurl

  • Select the “Shorten URL” option (in case you did not know, you can reveal that by touch­ing the mes­sage length counter in the cen­ter right of the screen).  In a few sec­onds, you should have a short URL going through your ser­vice.  If you did some­thing incor­rectly, Tweetie falls back to using bit.ly, so if you see a bit.ly URL, double-check what you entered as your cus­tom shortener.

    shorturl

And that’s all there is.  You now have Tweetie using your cus­tom URL short­en­ing service.

Share and Enjoy:
  • Digg
  • Reddit
  • del.icio.us
  • StumbleUpon
  • Yahoo! Buzz
  • Facebook
  • Google Bookmarks
  • Technorati

If you liked this post, you may also enjoy:

  1. Ninja Me!
  2. LJProxy: From friend-locked Live­Jour­nal posts to Google Reader
  3. Why I pre­fer Nambu as a Twit­ter client
  4. Yeay, Google!
  5. Good morn­ing!

{ 4 comments… read them below or add one }

1 Johnny Canuck January 14, 2010 at 10:55 am

Thanks Net Ninja Dude,

I managed to roll out yourls on our site yesterday and now thanks to this post, I can use my own service with Tweetie2. This is pretty cool, well done on putting this guide together.

Reply

2 Brian Enigma January 14, 2010 at 10:58 am

You’re welcome! I’m glad it was helpful. I was kind of unsure how useful it would be to others. Half the time when I post stuff like this, it’s to help me remember how I did it if I ever wipe out my settings.

Reply

3 JustinRez February 22, 2010 at 11:44 pm

Hi! I just set up Yourls on jta.gs (my name is Justin, so J Tags… *shrug)

I followed your directions and it worked perfectly! Thank you so much. This has really been a great help.

Reply

4 Brian Enigma February 26, 2010 at 10:54 am

Excellent! It’s great to hear when little things like this help out others!

Reply

Leave a Comment

Previous post:

Next post: