Reputation: 388
Have anyone used the function importRows() from fusion table API? As the API reference below, https://developers.google.com/fusiontables/docs/v1/reference/table/importRows I have to supply CSV data in the request body. But what should I do for the html body exactly?
My code:
http = getAuthorizedHttp()
DISCOVERYURL = 'https://www.googleapis.com/discovery/v1/apis/{api}/{apiVersion}/rest'
ftable = build('fusiontables', 'v1', discoveryServiceUrl=DISCOVERYURL, http=http)
body = create_ft(CSVFILE,"title here") # the function to load csv file and create the table with columns from csv file.
result = ftable.table().insert(body=body).execute()
print result["tableId"] # good, I have got the id for new created table
# I have no idea how to go on here..
f = ftable.table().importRows(tableId=result["tableId"])
f.body = ?????????????
f.execute()
Upvotes: 3
Views: 763
Reputation: 11
I fixed the problem like this:
media = http.MediaFileUpload('example.csv', mimetype='application/octet-stream', resumable=True)
request = service.table().importRows(media_body=media, tableId='1cowubQ0vj_H9q3owo1vLM_gMyavvbuoNmRQaYiZV').execute()
Upvotes: 1
Reputation: 388
I finally fixed my problem, my code can be found in the following link. https://github.com/childnotfound/parser/blob/master/uploader.py
Upvotes: 1