为了账号安全,请及时绑定邮箱和手机立即绑定

在python中通过api上传到Google Drive后如何获取链接?

在python中通过api上传到Google Drive后如何获取链接?

牧羊人nacy 2021-09-28 13:44:50
这里使用带有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'])有没有其他方法可以做到这一点。
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 180 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信