Google URL Shortener官方API

Google终于正式推出自家的URL Shortener http://goo.gl/供用户使用了。那么接口自然会是有的,不再需要像之前一样需要自己hack才能从外部调用goo.gl压缩网址。

API地址 http://goo.gl/api/shorten
参数 security_token 和 url
未登录就将security_token值设置未null

以下是Python代码写的示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/env python
# encoding: utf-8
import urllib,httplib
def test():
	url = 'goo.gl'
	form_fields = {'security_token':'null',
	               'url':'http://google.com'}
	params = urllib.urlencode(form_fields)
	headers = {'Host':'goo.gl',
               'User-Align':'Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.10',
               'Content-Type':'application/x-www-form-urlencoded; charset=UTF-8',
               'Connection':'Keep-Alive',
               'Keep-Alive':115,
               'X-Requested-With':'XMLHttpRequest',
               'Referer':'http://goo.gl/',
               'Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
               "Cookie":'authed=1'}
	conn = httplib.HTTPConnection(url)
	conn.request(method='POST',url = '/api/shorten',body=params,headers=headers)
	response = conn.getresponse()
	print response.status
 
	res = response.read()
	print res
 
	getheaders = response.getheaders()
	for head in getheaders:
	    print head[0],':',head[1]
	conn.close()
 
if __name__ == '__main__':
    test()

需要注意的是请求header信息里面必须携带Content-Type信息,否则会得到Bad request的400错误信息。
-EOF-

Python版支付宝交易接口

v2ex看到有同学在要Python版的接口,正好我最近做的东东有在做这个,抽时间处理了一下弄了个即时到帐和担保交易的Python版接口的出来。
演示 http://alipay-api.appspot.com
源代码 https://bitbucket.org/tearnon/alipay-python/

欢迎通过演示接口付款请我喝咖啡,嘻嘻。
-EOF-

Google Python Class Day

Google Python Class Day 1-1
[FMP]http://storage.ioio.name/tips/google-python-class/Google.Python.Class.Day.1.Part.1.flv[/FMP]

下载 [下载没有找到]

Google Python Class Day 1-2
[FMP]http://storage.ioio.name/tips/google-python-class/Google.Python.Class.Day.1.Part.2.flv[/FMP]

下载 [下载没有找到]

Google Python Class Day 1-3
[FMP]http://storage.ioio.name/tips/google-python-class/Google.Python.Class.Day.1.Part.3.flv[/FMP]

下载 [下载没有找到]

Google Python Class Day 2-1
[FMP]http://storage.ioio.name/tips/google-python-class/Google.Python.Class.Day.2.Part.1.flv[/FMP]

下载 [下载没有找到]

Google Python Class Day 2-2
[FMP]http://storage.ioio.name/tips/google-python-class/Google.Python.Class.Day.2.Part.2.flv[/FMP]

下载 [下载没有找到]

Google Python Class Day 2-3
[FMP]http://storage.ioio.name/tips/google-python-class/Google.Python.Class.Day.2.Part.3.flv[/FMP]

下载 [下载没有找到]
Google Python Class Day 2-4
[FMP]http://storage.ioio.name/tips/google-python-class/Google.Python.Class.Day.2.Part.4.flv[/FMP]

下载 [下载没有找到]

via 豆花@垃圾熊
-EOF-