Created
November 1, 2012 23:34
-
-
Save narphorium/3997537 to your computer and use it in GitHub Desktop.
Freebase mqlwrite
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pprint import pprint | |
from oauth2client.file import Storage | |
from oauth2client.client import OAuth2WebServerFlow | |
from oauth2client.tools import run | |
import json | |
from urllib import urlencode | |
import httplib2 | |
DEVELOPER_KEY=""; | |
CLIENT_ID="" | |
CLIENT_SECRET="" | |
def authenticated_http(): | |
storage = Storage('freebase.dat') | |
credentials = storage.get() | |
if credentials is None or credentials.invalid == True: | |
flow = OAuth2WebServerFlow( | |
client_id=CLIENT_ID, | |
client_secret=CLIENT_SECRET, | |
scope='https://www.googleapis.com/auth/freebase', | |
user_agent='freebase-cmdline-sample/1.0', | |
xoauth_displayname='Freebase Client Example App') | |
credentials = run(flow, storage) | |
http = httplib2.Http() | |
return credentials.authorize(http) | |
def main(): | |
http = authenticated_http() | |
query = {"create":"unconditional","id":None,"name":"Nowhere","type":"/location/location"} | |
data = dict(query=json.dumps(query)) | |
headers = { | |
'X-HTTP-Method-Override': 'GET', | |
'Content-Type': 'application/x-www-form-urlencoded' | |
} | |
url = 'https://www.googleapis.com/freebase/v1-sandbox/mqlwrite' + '?' + urlencode(data) | |
resp, content = http.request(url, "GET", headers=headers) | |
print content | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment