融合表导入

2024-06-23 19:01:38 发布

您现在位置:Python中文网/ 问答频道 /正文

有人使用过fusion table API中的importRows()函数吗? 作为以下API参考, https://developers.google.com/fusiontables/docs/v1/reference/table/importRows 我必须在请求正文中提供CSV数据。 但是对于html主体我该怎么做呢?在

我的代码:

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()

Tags: thehttpscomapihttpcreatetablebody
2条回答

我终于解决了我的问题,我的代码可以在下面的链接中找到。 https://github.com/childnotfound/parser/blob/master/uploader.py

我这样解决了这个问题:

media = http.MediaFileUpload('example.csv',  mimetype='application/octet-stream', resumable=True)
request = service.table().importRows(media_body=media, tableId='1cowubQ0vj_H9q3owo1vLM_gMyavvbuoNmRQaYiZV').execute()

相关问题 更多 >

    热门问题