Google API örneklerinde heck "MediaFileUpload" un nereden geldiğini anlamaya çalışırken bu soruyu buldum ve sonunda bunu çözdüm. İşte Python 2.7 ile şeyleri test etmek için kullandığım daha eksiksiz bir kod örneği.
Bu kodun çalışması için bir JSON kimlik bilgisi dosyasına ihtiyacınız var. Bu, Google uygulamanızdan/projenizden/şeyinizden aldığınız kimlik bilgileri dosyasıdır.
Yüklemek için bir dosyaya da ihtiyacınız var, ben örnekte "test.html" kullanıyorum.
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'))
"beden" kullanmak için geçerli Mime Türleri listesi karma https://developers.google.com/drive/v3/web/mime-types
de MediaFileUpload için geçerli mimetype dizeleri listesi (onlar için dosyanızı dönüştürmek deneriz kullanılabilir neyse siz) burada koyun:
https://developers.google.com/drive/v3/web/integrate-open#open_files_using_the_open_with_contextual_menu
Tabii, biz kesinlikle size yardımcı olabilir. Neye sahipsin? Yapıştır ve tamir edebiliriz. Bu arada, şunu gördünüz mü: https://code.google.com/p/google-drive-sdk-samples/source/browse/#hg%2Fpython –
Bu kodun her yerinde bulundum, ancak denerken Bunu kullanmak için, JSON'u göndermek istediğiniz formun herhangi bir örneğini bulamadınız. Bana bununla yardım edebilir misin? Form nasıl görünmeli? – user1501783
Bu sayfaya göz atın: https://developers.google.com/drive/v3/web/folder#inserting_a_file_in_a_folder bir kullanım örneğine sahiptir ve size yardımcı olabilir – Greg