Jump to content
roza

google url shortener

Recommended Posts

I was trying to turn Mike Walker's url shortener extension into an Alfred 2 Workflow but failed. Anyone else know how to do this? Here is the link to the extension: http://incredimike.com/projects/alfred-gurl/

 

You would do it like this:

 

Screenshot_3_14_13_2_27_PM-5.jpg

 

And the script would look like this:

 

 

# longURL supplied by user
$longUrl = "{query}";
 
# Use commandline curl because it's good at these sort of things
$resp = `curl --silent https://www.googleapis.com/urlshortener/v1/url -H 'Content-Type: application/json' -d '{"longUrl": "$longUrl"}'`;
 
# Use JSON extension added in PHP 5.2
$json = json_decode( $resp );
 
# Echo out the URL.
echo $json->id;

Share this post


Link to post

Hi, thanks! I recreated this but unfortunately, I don't get the shortened url, just the url I started out with. Would you be so kind as to provide your workflow so I can see what I did wrong?

Share this post


Link to post

Thanks macbookandrew and of course Mike for the initial shortener (even though there was already one ;))

 

Thanks of course Andrew and Vero too.

 

There are many reasons to love Alfred and this is just one example - the first url shortener I used stopped working, quick Google and got Mikes version (much quicker than diagnosing/testing etc.). Then v2 Alfred comes round, url shortener and snippets gone! I upgraded early. Very short time later import doodads sorted out. Done that, then quick hunt and shortener found (here).

 

No wonder Alfred receives so much love. Deservedly so.

 

R!

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...