답변

0

시도는 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를 지정해야합니다.