擅长:python、mysql、java
<p>在<a href="http://code.google.com/p/google-api-python-client/" rel="nofollow">Google API Python Client</a>的下一个版本(版本1.0 beta 9)中,您将能够像这样将多个查询批处理在一起:</p>
<pre><code>from apiclient import discovery, model
from apiclient.http import BatchHttpRequest
import json
DEVELOPER_KEY = open('DEVELOPER_KEY').read()
query1 = [{"name~=":"*doubt*","name":None,"type":"/media_common/quotation","author":[{"name":"William Shakespeare"}]}]
query2 = [{"name~=":"*law*","name":None,"type":"/media_common/quotation","author":[{"name":"William Shakespeare"}]}]
model.JsonModel.alt_param = ""
freebase = discovery.build('freebase', 'v1', developerKey=DEVELOPER_KEY)
def display_results(request_id, response):
for topic in response['result']:
print topic['name']
batch = BatchHttpRequest(callback=display_results)
batch.add(freebase.mqlread(query=json.dumps(query1)))
batch.add(freebase.mqlread(query=json.dumps(query2)))
batch.execute(http)
</code></pre>
<p>使用这种技术,您可以组合多个查询,甚至MQL查询和搜索查询,它将只创建一个HTTP请求。在</p>