Код: Выделить всё
import google.auth
from googleapiclient.discovery import build
from googleapiclient.errors import HttpError
from googleapiclient.http import MediaFileUpload
from google.oauth2.service_account import Credentials
def copy_file_to_folder(file_id, destination_folder_id):
creds = Credentials.from_service_account_file('service_account.json')
try:
service = build('drive', 'v3', credentials=creds)
file = service.files().get(fileId=file_id).execute()
file['parents'] = [destination_folder_id]
copied_file = service.files().copy(fileId=file_id, body=file, fields='id').execute()
return copied_file['id']
except HttpError as error:
print(f'An error occurred: {error}')
return None
if __name__ == "__main__":
file_id = 'File ID I wanted to copy'
destination_folder_id = 'Destination folder ID to put the copy in'
copy_file_to_folder(file_id, destination_folder_id)
Код: Выделить всё
An error occurred:
Подробнее здесь: https://stackoverflow.com/questions/791 ... -script-to