Malleable Musings

April 25, 2009

Cli.gs and the iPhone – Part 3 (Twitterfon)

Filed under: cli.gs, iphone, PHP, simple hacks — Tags: , , — Brendan @ 10:04 pm

Twitterfon is definitely my favourite Twitter client for the iPhone.  Although I still haven’t tried Tweetie but according to this post there really isn’t much in it.  So I was excited earlier this evening to discover the bookmarklet on the Naan Studio website (hadn’t realised that they also produced the excellent Twitterfox add-in for Firefox as well).

On using the bookmark I noticed whilst it posts shortish URL’s in full for long URL’s it uses the tinyurl.com shortener.  I’ve nothing against tinyurl, in fact many years ago I used to use them extensively when sending bulk email however today there are much better URL shortners to choose from.  So I hacked together a little PHP script to create private cli.gs (N.B. you’ll need to add your cli.gs API key in the place indicated).

<?php
$url = $_GET['url'];
$title = $_GET['title'];
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_VERBOSE, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, "http://cli.gs/api/v1/cligs/create?
              key=[API key goes here]&appid=BFphpscript&url=".urlencode($url)."&title=".urlencode($title));
$output = curl_exec($ch);
curl_close($ch);
header("location: twitterfon:///post?".$output);
?>

You’d then need to call it in the usual way – i.e. via a bookmark of

javascript:(function(){%20window.open('[location of php script]?url='
+encodeURIComponent(location.href)%20+'&title='+encodeURIComponent(document.title));%20})();

I’m hoping that eventually I’ll figure out a better final line of the php script, i.e. something that can transfer more than just the URL over to Twitter, unfortunately there’s very little documentation for Twitterfon, the only thing I found other than on the Naan website was this piece from someone who had a similar idea of using a php script a couple of weeks ago.

Advertisements

December 28, 2008

Cligs and the iPhone – Part II

Filed under: cli.gs, iphone — Tags: — Brendan @ 8:42 pm

I posted previously about a better alternative to Twitterlink on the iPhone. A javascript function that calls cli.gs directly. (Cli.gs is a URL shortening service with analytics – great for measuring impact on a newsfeed from Twitter or elsewhere.)

Thanks to Pierre at cli.gs, I’ve now improved this by creating several javascript functions as bookmarks that call a PHP script, passing specific variables. e.g. this function passes an action that I’m “Reading about ” the “document title” and the “URL” to the script which calls the cli.gs API and returns the results as a parameter to the Twitter homepage (checking that it meets Twitter’s character limit).

N.B. I decided this was preferable rather than posting directly to Twitter as it allows a review before posting, however I might change this in the future.


javascript:(function(){%20window.open('[location of php script]?url='+encodeURIComponent(location.href)%20+'&act=Reading%20about%20&title='+encodeURIComponent(document.title));%20})();

I’ve already completed the same bookmark for “Commenting on ” and making a “New post “. I’ll see what other actions I will find useful over the next few days.

If you are interested in implementing something like this for yourself. You’ll need a bit of webspace where you can run PHP.

The PHP script is simple enough (and most of it is courtesy of Thor Erik’s rater than me) however I’m sure it can probably be improved and suggestions will be gratefully recieved.

If you do want to use this you’ll need to alter [my api key] to your own cli.gs API key and then upload the script.  Then all you need to do is change [location of php script] in the Javascript calls and work out what actions you want (remember to use %20 instead of spaces) when you’re setting your bookmarks.


<?php
$act = $_GET['act'];
$url = $_GET['url'];
$title = $_GET['title'];
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_VERBOSE, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, "http://cli.gs/api/v1/cligs/create?key=[my api key]&appid=BFphpscript&url=".urlencode($url)."&title=".urlencode($title));
$output = curl_exec($ch);
curl_close($ch);
if (strlen($title) < (137 - strlen($act) - strlen($output))) {
$status = $act . $title . "%20-%20" . $output;
}
else {
$status = $act . substr($title, 0, (137 - strlen($act) - strlen($output))) . "%20-%20" . $output;
}
echo $status;
header("location: http://twitter.com/home?status=".$status);
?>

December 22, 2008

Cli.gs and the iPhone

Filed under: cli.gs, iphone — Brendan @ 11:25 pm

I’ve been flirting with Twitter recently and exploring various different clients on my iPhone including Twitteriffic, TwitterFon, Twinkle and Twitterlink which are all available through the AppStore.

I’m currently running several Twitter accounts, one of which is a pure newsfeed which is usually managed through Twitterfeed.  This is pushing various RSS feeds out for me, however not all link back to a site on which I’m running Analytics.

The default URL shortening service in Twitterfeed is TinyURL.  However today I changed this to Cli.gs which for me has several advantages:

  1. a shorter character count
  2. tracking (including hits over time, geo-location of hits, referrer counting, and social media counts)
  3. it works brilliantly with the iPhone as it’s a javascript call.

In a sense it replaces Twitterlink entirely for me and it has the advantage of pushing a shortened trackable URL.

To install on the iPhone it’s the usual trick of bookmarking a URL e.g. https://malleablemusings.wordpress.com/2008/12/22/?javascript:(function(){ window.open(‘http://cli.gs/cligs/new?url=’+encodeURIComponent(location.href)+’&amp;title=’+encodeURIComponent(document.title)); })();

and then going in to edit your bookmark by deleting everything before the word javascript.

Brilliant!