Encontré esta pregunta mientras intentaba averiguar de dónde venía el "MediaFileUpload" en los ejemplos de API de Google, y finalmente lo descubrí. Aquí hay un ejemplo de código más completo que usé para probar cosas con Python 2.7.
Necesita un archivo de credenciales JSON para que funcione este código. Este es el archivo de credenciales que obtienes de tu aplicación/proyecto/cosa de Google.
También necesita un archivo para cargar, estoy usando "test.html" aquí en el ejemplo.
from oauth2client.service_account import ServiceAccountCredentials
from apiclient.discovery import build
from apiclient.http import MediaFileUpload
#Set up a credentials object I think
creds = ServiceAccountCredentials.from_json_keyfile_name('credentials_from_google_app.json', ['https://www.googleapis.com/auth/drive'])
#Now build our api object, thing
drive_api = build('drive', 'v3', credentials=creds)
file_name = "test"
print "Uploading file " + file_name + "..."
#We have to make a request hash to tell the google API what we're giving it
body = {'name': file_name, 'mimeType': 'application/vnd.google-apps.document'}
#Now create the media file upload object and tell it what file to upload,
#in this case 'test.html'
media = MediaFileUpload('test.html', mimetype = 'text/html')
#Now we're doing the actual post, creating a new file of the uploaded type
fiahl = drive_api.files().create(body=body, media_body=media).execute()
#Because verbosity is nice
print "Created file '%s' id '%s'." % (fiahl.get('name'), fiahl.get('id'))
Una lista de tipos MIME válidos para utilizar en el "cuerpo" hash es disponible en https://developers.google.com/drive/v3/web/mime-types
Una lista de cadenas Mimetype válidos para el MediaFileUpload (que van a tratar de convertir el archivo a cualquier pones aquí):
https://developers.google.com/drive/v3/web/integrate-open#open_files_using_the_open_with_contextual_menu
Claro, podemos ayudarle definitivamente. ¿Qué tienes? Pégalo y podemos arreglarlo. ¿Has visto esto, por cierto: https://code.google.com/p/google-drive-sdk-samples/source/browse/#hg%2Fpython –
He estado hablando de ese código, pero al intentarlo para usarlo, no pudo encontrar ningún ejemplo de qué forma le gustaría publicar el JSON. ¿Me puede ayudar con eso? ¿Cómo debería ser la forma? – user1501783
Echa un vistazo a esta página: https://developers.google.com/drive/v3/web/folder#inserting_a_file_in_a_folder tiene un ejemplo de uso y puede ser capaz de ayudarte – Greg