Page 1 of 1

goo.gl

Posted: Wed Feb 01, 2017 5:05 pm
by gbcox
Has anyone attempted to create an action for goo.gl? I've tried using the javascript and keep getting:
SyntaxError: missing ) after argument list

openURL("https://www.googleapis.com/urlshortener ... =mykeyhere -H 'Content-Type: 'application/json' -d '{"longUrl":"{fullURL}"}")

So as an alternate approach I though of just creating a custom action using http://goo.gl and then using copystring:{fullURL}

but I can't figure out a way to just have the clipboard to just have the contents of {fullURL} - it copies the entire url specified including "https://goo.gl"

any suggestions? Thanks!

Re: goo.gl

Posted: Thu Feb 02, 2017 12:18 am
by DaveG
On searching for docs for Google's API here, I came across this:
https://developers.google.com/url-short ... ng_started

The "-H" and "-d" stuff are switches to the "curl" command to specify the header and post data, not parts of a URL. If you were to use the POST API, it would only return a bit of JSON and not a page to load, anyway, so it's not ideal. They don't seem to have a REST API, which is what you'd normally use with Flagfox.

The copystring pseudo-protocol only copies a string to the clipboard so you can paste it elsewhere. It's not what you want here.

A formfield Flagfox action would normally be the simplest route here, however the goo.gl input box isn't in a proper form and has no id/name and Google has a captcha to intentionally make it not automatable.

Now, all the normal stuff out the window, it's time to go fully manual and do a POST request:

Code: Select all

javascript:var r = new XMLHttpRequest(); r.open("POST","https://www.googleapis.com/urlshortener/v1/url"); r.setRequestHeader("Content-Type","application/json"); r.onreadystatechange = function(e) { if (r.readyState == XMLHttpRequest.DONE) alert(r.response); }; r.send("{\"longUrl\": \"{fullURL}\"}");
This probably works ok, but it currently returns a complaint that I've exceeded my daily unauthenticated use limit from just testing this to try and get it to work, so I guess it's not much use without an API key. Again, whilst it can probably create the shortened URL, Google just spits back some not-user-friendly JSON when you use this API.

Bottom line: There's no clean way to do this that will result in an easy automated action and a friendly result page. Google made sure to prevent that. Manually kludging it might work, but at this point I'd just be using a different shortener service, personally.

Re: goo.gl

Posted: Thu Feb 02, 2017 2:15 am
by gbcox
I got a key and it works and allows me to copy the shorturl: here is the full string:

Code: Select all

javascript:var r = new XMLHttpRequest(); r.open("POST","https://www.googleapis.com/urlshortener/v1/url?key=YOUR_KEY_GOES_HERE"); r.setRequestHeader("Content-Type","application/json"); r.onreadystatechange = function(e) { if (r.readyState == XMLHttpRequest.DONE) alert(r.response); }; r.send("{\"longUrl\": \"{fullURL}\"}");
The command doesn't give a url that you can track in your Google Account... I'll read and see if I can figure that out. Half way there...

Thanks much!