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-

《Dive Into Python 3》中文版

Mark Pilgrim的《Dive Into Python》的升级版《Dive Into Python 3》针对 Python 3 进行了更新。现在这本书已经有了中文版,由啄木鸟社区翻译。

在线阅读 http://www.woodpecker.org.cn/share/projects/diveintopython3/
中文镜像 http://diveintopython3.com/
英文原版 http://diveintopython3.org/

在此感谢啄木鸟社区对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]

下载 [download id=”29″]

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

下载 [download id=”30″]

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

下载 [download id=”31″]

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

下载 [download id=”32″]

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

下载 [download id=”33″]

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

下载 [download id=”34″]
Google Python Class Day 2-4
[FMP]http://storage.ioio.name/tips/google-python-class/Google.Python.Class.Day.2.Part.4.flv[/FMP]

下载 [download id=”35″]

via 豆花@垃圾熊
-EOF-