1

我想将 aj 图片上传到 Google Drive。该图像位于我上传图像的脚本的同一目录中。我在 script.py 文件中有这段代码

#!/usr/bin/python

import httplib2
import pprint
from apiclient.discovery import build
from apiclient.http import MediaFileUpload
from oauth2client.client import OAuth2WebServerFlow

filename = 'image.jpg'
mimetype = 'image/jpg'

drive_service = build('drive', 'v2', developerKey='MY Simple API Access KEY')

# Insert a file
media_body = MediaFileUpload(filename, mimetype=mimetype, resumable=True)
body = {
    'title': 'This is an image',
    'description': 'This is a description',
    'mimeType': mimetype
}

file = drive_service.files().insert(body=body, media_body=media_body).execute()

pprint.pprint(file)

运行python script.py时出现此错误:

Traceback (most recent call last):
  File "script.py", line 22, in <module>
    file = drive_service.files().insert(body=body, media_body=media_body).execute()
  File "/usr/local/lib/python2.7/dist-packages/oauth2client/util.py", line 120, in positional_wrapper
    return wrapped(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/apiclient/http.py", line 656, in execute
    _, body = self.next_chunk(http=http)
  File "/usr/local/lib/python2.7/dist-packages/oauth2client/util.py", line 120, in positional_wrapper
    return wrapped(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/apiclient/http.py", line 733, in next_chunk
    raise ResumableUploadError("Failed to retrieve starting URI.")
apiclient.errors.ResumableUploadError: Failed to retrieve starting URI.
4

1 回答 1

1

您没有正确执行授权,请查看 Google Drive SDK 文档中的快速入门以获取分步说明:

https://developers.google.com/drive/quickstart

于 2012-10-04T21:21:23.627 回答