我在heroku上运行一个网络应用程序,我的目标是通过向应用程序发送命令,使用Google Drive API for python复制我自己的驱动器中的文件。
到目前为止,我有这段代码:
import os
import json
import gspread
from oauth2client.service_account import ServiceAccountCredentials
import httplib2
from apiclient import discovery
# use creds to create a client to interact with the Google Drive API
scope = ['https://www.googleapis.com/auth/drive']
creds = ServiceAccountCredentials.from_json_keyfile_dict(json.loads(os.environ.get('CREDENTIALS')), scope)
client = gspread.authorize(creds)
http = creds.authorize(httplib2.Http())
service = discovery.build('drive', 'v3', http=http, cache_discovery=False)
folder = "12vQQwYK5bkg-6UKoNrXpsU1C1-fiYeTX" # folder ID
file = "1EA25-BYr1AAUUDcstfVowDeGoygMGuxKxGxFYEdKTX0" # file ID
title = "New_file_id"
service.files().copy(fileId=file,
body={"parents": [{"kind": "drive#fileLink",
"id": folder}], 'title': title}).execute()
但它永远停留在执行POST请求上。我做错了什么?
答案 0 :(得分:1)
使用Drive API v3时,请使用name
来提供文件名,而不是title
。请将kind
放在parents
的外面。那么body
的以下修改怎么样?
{
"parents": [{"kind": "drive#fileLink", "id": folder}],
'title': title
}
{
"parents": [folder],
"name": title,
"kind": "drive#fileLink"
}
如果这没有导致解决方案,我很抱歉。