Media Temple ProDev API

Media Temple也耐不住寂寞出API了,这年头不提供API的服务不是好服务。既然有API那就试试吧。登录帐号,获取api key以后便可以开始编程了。
需要注意的是尽管文档里有提全局的HTTP 请求headers里包含Authorization为api key用以访问api。但我发现使用header的形式并不能访问成功,实际的api key还是需要在URL里以参数的形式携带(API Query parameters)。
以下示例用以访问Get all service details接口。

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
#!/usr/bin/env python
# encoding: utf-8
"""
mtapi.py
 
Created by 枯藤昏鸦 on 2011-05-14.
Copyright (c) 2011 IoIo.NaMe. All rights reserved.
"""
import urllib,httplib
 
def main():
url = 'api.mediatemple.net'
apikey = 'your api key'
urls = '/api/v1/services.json?apikey='+apikey
form_fields = {}
params = urllib.urlencode(form_fields)
headers = {}
conn = httplib.HTTPSConnection(url)
conn.request(method='GET', url=urls, body=params, headers=headers)
response = conn.getresponse()
res = response.read()
h = response.getheaders()
print 'Response Status:',response.status
print 'Response Header:'
for i in h:
print i[0],':',i[1]
print 'Response Content:',res
conn.close()
 
if __name__ == '__main__':
main()

记得是使用https链接(httplib.HTTPSConnection)。
相关资料:API文档(PDF)
-EOF-