Здесь я использую API Google Drive с Python для загрузки файлов на 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'])
Есть ли альтернативный способ сделать это.
заранее спасибо.