Automating short URL creation on iOS

 Requirements

 Drafts action

pythonista://shortenURL?action=run&argv=[[title]]

 Pythonista script

import urllib
import json
import webbrowser
import sys

url = sys.argv[1]
api = 'https://api-ssl.bitly.com/v3/shorten'
token = 'Insert your token here'
request = api + '?access_token=' + token + '&longURL=' + url

usock = urllib.urlopen(request)
data = usock.read()
dataJSON = json.loads(data)
shortURL = dataJSON["data"]["url"]

outputURL = 'drafts://x-callback-url/create?text=' + shortURL

webbrowser.open(outputURL)
usock.close()

 Usage

 Notes

If you do not have Pythonista this could be accomplished in a slightly less automated fashion using bitly’s x-callback-url scheme. When I looked into this I had no luck getting the x-success parameter to work though.

It is also worth noting that you must ensure your Pythonista script has the same name as the script you are calling in the first parameter of the Drafts action.

 Acknowledgements

Special thanks to Federico Viticci and Alex Guyot for the inspiration.

 
18
Kudos
 
18
Kudos

Now read this

BookNet Canada Tech Forum 2014 Reading Recommendations

It’s Complicated: The Social Lives of Networked Teens Danah Boyd Creativity, Inc.: Overcoming the Unseen Forces That Stand in the Way of True Inspiration Ed Catmull Just Enough Research (A Book Apart #9) Erika Hall Smarter Than You... Continue →