Anonymous     Python     31 Aug 2011    
 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
import httplib2
import json
URL = 'https://sandbox.mobileworks.com/api/v1/tasks/'
USERNAME = 'foo'
PASSWORD = 'fo\''
def main():
connection = httplib2.Http()
connection.add_credentials(USERNAME, PASSWORD)
headers = {'Content-Type': 'application/json'}
query = {
'question': 'your instructions here' ,
'resource':'http://anylinkhere.com',
'answerType': 't',
'resourceType': 'l'
}
response, content = connection.request(URL, method='POST', body=json.dumps(query),
headers=headers)
if (response.status == 201):
print response['location']
else:
raise Exception(response.status)
if __name__ == '__main__':
main()