Skip to content

Instantly share code, notes, and snippets.

@andreagrandi
Created July 19, 2013 11:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andreagrandi/6038405 to your computer and use it in GitHub Desktop.
Save andreagrandi/6038405 to your computer and use it in GitHub Desktop.
An example of Bitly API use.
import requests
from urllib import urlencode
token = '**************************************************'
url_base = 'https://api-ssl.bitly.com/v3/'
url = 'http://www.repubblica.it'
parameters = [('access_token', token), ('longUrl', url)]
request = requests.get(url_base + 'shorten/', params = urlencode(parameters))
short_url = request.json()['data']['url']
hash_code = request.json()['data']['hash']
parameters = [('access_token', token), ('hash', hash_code)]
request = requests.get(url_base + 'info', params = urlencode(parameters))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment