0
이 쿼리 http://mql.freebaseapps.com/ch04.html에있는 freebase에 대한 단일 호출로 여러 쿼리의 결과를 얻고 싶습니다. 파이썬을 쿼리에 사용하고 있습니다. 나는이Freebase에 대한 단일 호출로 여러 쿼리 실행
{ # Start the outer envelope
"q1": { # Query envelope for query named q1
"query":{First MQL query here} # Query property of query envelope
}, # End of first query envelope
"q2": { # Start query envelope for query q2
"query":[{Second MQL query here}] # Query property of q2
} # End of second query envelope
}
처럼 쿼리하고 해당 링크에 지정된대로
{
"q1": {
"result":{First MQL result here},
"code": "/api/status/ok"
},
"q2": {
"result":[{Second MQL result here}],
"code": "/api/status/ok"
},
"status": "200 OK",
"code": "/api/status/ok",
"transaction_id":[opaque string value]
}
같은 답변을 얻을 싶어요.
하지만 그들은 "api.freebase.com"입니다 기존의 API를 사용하는 것 같다 - 나는 또한있는, SO에 질문의 일부를 가로 질러왔다. 업데이트 된 API는 "www.googleapis.com/freebase"입니다.
다음 코드를 시도했지만 작동하지 않습니다.
import json
import urllib
api_key = "freebase_api_key"
service_url = 'https://www.googleapis.com/freebase/v1/mqlread'
query1 = [{'id': None, 'name': None, 'type': '/astronomy/planet'}]
query2 = [{'id': None, 'name': None, 'type': '/film/film'}]
envelope = {
'q1':query1,
'q2':query2
}
encoded = json.dumps(envelope)
params = urllib.urlencode({'query':encoded})
url = service_url + '?' + params
print url
response = json.loads(urllib.urlopen(url).read())
print response
나는 하나의 MQL 쿼리에 여러 개의 쿼리를 삽입 할 수있는 방법
{u'error': {u'code': 400, u'message': u'Type /type/object does not have property q1', u'errors': [{u'domain': u'global', u'message': u'Type /type/object does not have property q1', u'reason': u'invalid'}]}}
로 오류가 발생하고 난에 대한 Python 클라이언트 라이브러리의 Batch 능력을보고 좋을 것