Как-то били не очень стабильно работает, но скрипт где то у меня был на Питоне:
PHP код:
from google.appengine.api import urlfetch
from urllib import quote, unquote, urlencode
from settings import BITLY_LOGIN, BITLY_KEY
try:
import json
except ImportError:
import simplejson as json
def bit_shorten(uri):
params = {'login' : BITLY_LOGIN,
'apiKey' : BITLY_KEY,
'domain' : "bit.ly",
'uri' : uri.encode('utf8'),
}
bit_url = "http://api.bit.ly/v3/shorten?%s" % urlencode(params, doseq=True)
try:
res = urlfetch.fetch(bit_url)
except urlfetch.DownloadError, msg:
logging.error(str(msg) + ": bitly mazafaka")
return ""
if res.status_code != 200:
logging.warning(res.status_code)
if res.content:
logging.warning(res.content)
return ""
try:
jj = json.loads(res.content)
except Exception, msg:
logging.error(msg)
return ""
if jj["status_txt"] != "OK":
logging.error(jj["status_txt"])
return ""
else:
return jj["data"]["url"]