这里使用带有python的google drive API将文件上传到google drive,我如何获取上传文件的链接。
我试过print (res['exportLinks']),但它给了我这个错误。
KeyError: 'exportLinks'
完整的python代码
#!/usr/bin/env python
from __future__ import print_function
import os
from apiclient import discovery
from httplib2 import Http
from oauth2client import file, client, tools
SCOPES = 'https://www.googleapis.com/auth/drive'
store = file.Storage('storage.json')
creds = store.get()
if not creds or creds.invalid:
flow = client.flow_from_clientsecrets('client_secrets.json', SCOPES)
creds = tools.run_flow(flow, store)
DRIVE = discovery.build('drive', 'v2', http=creds.authorize(Http()))
FILES = (('hello.txt', False),)
for filename, convert in FILES:
metadata = {'title': filename}
res = DRIVE.files().insert(convert=convert, body=metadata,
media_body=filename, fields='mimeType,exportLinks').execute()
if res:
print (res['exportLinks'])
有没有其他方法可以做到这一点。
相关分类