这里使用带有python的google drive API将文件上传到google drive,我如何获取上传文件的链接。我试过print (res['exportLinks']),但它给了我这个错误。KeyError: 'exportLinks'完整的python代码#!/usr/bin/env pythonfrom __future__ import print_functionimport osfrom apiclient import discoveryfrom httplib2 import Httpfrom oauth2client import file, client, toolsSCOPES = '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'])有没有其他方法可以做到这一点。
添加回答
举报
0/150
提交
取消