編集:これは、メタデータにアクセスし、ID で既存のファイルのコンテンツを取得および設定する方法です。
# Calling CreateFile() with an existing ID links it to the already existing file.
gdrive_file = drive.CreateFile({'id': '<your file id>'})
gdrive_file.FetchMetadata() # Only needed if you want to view or edit its metadata.
# Do things with metadata here as needed.
gdrive_file.GetContentFile('dog.png') # Download content file.
# And/or upload a new content file.
gdrive_file.SetContentFile('cat.png')
gdrive_file.Upload()
そしてもちろん、ドキュメントにはたくさんの例があります。
オリジナル:例については、ファイル リストのドキュメントを参照してください。
あなたが
=
看板の周りに自分の空間を紹介するのではなく、
- PyDrive は Google Drive API v2 を使用するため、代わりにv2 検索パラメーター ページを使用してください。
- ID は、Google ドライブによって割り当てられたフォルダー ID です。この SO の質問には、ID を見つける方法がリストされています。
例えば:
from pydrive.drive import GoogleDrive
drive = GoogleDrive(gauth) # Create GoogleDrive instance with authenticated GoogleAuth instance
folder_id = "insert your folder ID here"
# Auto-iterate through all files in the specified folder.
file_list = drive.ListFile({
'q': "{id} in parents and trashed=false".format(id=folder_id)
}).GetList()
for file1 in file_list:
print('title: %s, id: %s' % (file1['title'], file1['id']))