使用云端硬盘API在Google云端硬盘中创建空电子表格 [英] Creating empty spreadsheets in Google Drive using Drive API

查看:129
本文介绍了使用云端硬盘API在Google云端硬盘中创建空电子表格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Google云端硬盘中创建一个空的Google表格(仅使用元数据创建).当我提到Google SpreadSheet API 文档时,它说使用了DocumentsList API,但已弃用,而是要求我使用Google Drive API.在Drive API文档中,我找不到创建空工作表的任何方法.有人知道如何执行此操作吗?

I want to create an empty Google Sheet (created only with metadata) in Google Drive. When I referred to the Google SpreadSheet API documentation, it says to use the DocumentsList API, but it's deprecated and instead asks me to use the Google Drive API. In the Drive API docs, I could not find any way to create an empty Sheet. Anyone have a clue on how to do this?

推荐答案

您可以使用 MIME类型设置为application/vnd.google-apps.spreadsheet,来"nofollow noreferrer>驱动器API :

You can do this using the Drive API by setting the MIME type to application/vnd.google-apps.spreadsheet:

要在Python中执行此操作:

To do this in Python:

from apiclient.discovery import build
service = build('drive', 'v2')

import httplib2
credentials = ... # Obtain OAuth 2.0 credentials
http = credentials.authorize(httplib2.Http())

body = {
  'mimeType': 'application/vnd.google-apps.spreadsheet',
  'title': 'Name of Spreadsheet',
}
file = service.files().insert(body=body).execute(http=http)
# or for version 3 it would be
# file = service.files().create(body=body).execute(http=http)

转到 Google API浏览器试用!

这篇关于使用云端硬盘API在Google云端硬盘中创建空电子表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆