0
웹 인터페이스를 만들었으며 드라이브 API가 포함 된 빈 Google 스프레드 시트를 만들려고합니다.드라이브 API를 사용하여 빈 Google 스프레드 시트를 만들려면 어떻게해야합니까?
빈 Google 스프레드 시트는 어떻게 만듭니 까?
웹 인터페이스를 만들었으며 드라이브 API가 포함 된 빈 Google 스프레드 시트를 만들려고합니다.드라이브 API를 사용하여 빈 Google 스프레드 시트를 만들려면 어떻게해야합니까?
빈 Google 스프레드 시트는 어떻게 만듭니 까?
시도는 MIME Type
from apiclient import errors
from apiclient.http import MediaFileUpload
# ...
def insert_file(service, title, description, parent_id, mime_type, filename):
"""Insert new file.
Args:
service: Drive API service instance.
title: Title of the file to insert, including the extension.
description: Description of the file to insert.
parent_id: Parent folder's ID.
mime_type: MIME type of the file to insert.
filename: Filename of the file to insert.
Returns:
Inserted file metadata if successful, None otherwise.
"""
media_body = MediaFileUpload(filename, mimetype=mime_type, resumable=True)
body = {
'title': title,
'description': description,
'mimeType': mime_type
}
# Set the parent folder.
if parent_id:
body['parents'] = [{'id': parent_id}]
try:
file = service.files().insert(
body=body,
media_body=media_body).execute()
# Uncomment the following line to print the File ID
# print 'File ID: %s' % file['id']
return file
except errors.HttpError, error:
print 'An error occured: %s' % error
return None
application/vnd.google-apps.spreadsheet
에주의를 설정하여 Drive API를 사용 : files.insert과 앱 바로 가기 작성은 MIME 타입 응용 프로그램/vnd.google-apps.drive-SDK를 지정해야합니다.