Lin*_*say 6 python google-app-engine google-drive-api
我有一个现有的Google App Engine Python应用程序,它具有很多功能.我现在想要将Google云端硬盘集成到应用中.具体来说,我希望我的应用能够:
如果有人知道如何做我想做的事情,可以将我引导到符合我的SPECIFIC要求的SPECIFIC Google网页(不是像"DrEdit示例"这样的一般答案),我将永远感激不尽. .提前致谢!
更新:
根据drive-v2-python-appengine在答案1中的建议生成的示例代码,这是我的程序,其中包含用于创建空文件的RequestHandler:
import os
import webapp2
import io
from google.appengine.api import memcache
import httplib2
from apiclient.discovery import build
from apiclient.http import MediaIoBaseUpload
from oauth2client.appengine import oauth2decorator_from_clientsecrets
decorator = oauth2decorator_from_clientsecrets(
os.path.join(os.path.dirname(__file__), 'client_secrets.json'),
scope=[
'https://www.googleapis.com/auth/drive',
])
http = httplib2.Http(memcache)
drive_service = build("drive", "v2", http=http)
class CreateEmptyFile(webapp2.RequestHandler):
@decorator.oauth_required
def get(self):
body = {
'title': 'Sample Document',
'description': 'A sample document',
'mimeType': 'text/plain'
}
media_body = MediaIoBaseUpload(io.BytesIO(""), mimetype='text/plain', resumable=True)
file = drive_service.files().insert(body=body, media_body=media_body).execute()
self.redirect("/synopsis")
Run Code Online (Sandbox Code Playgroud)
测试有点令人困惑,因为偶尔当我运行它时,包括第一次,它会启动访问请求页面,但大多数情况下它没有.我已经使用https://accounts.google.com/b/0/IssuedAuthSubTokens?hl=zh-CN撤消对驱动器和云端硬盘的访问权限不再显示在列表中,但我想存在一小时或更长时间的延迟用于执行访问撤销.不确定,并没有看到它记录.
在任何情况下,如果我将呼叫注释掉drive_service.files().insert(),它就不会中止,并重定向到我的概要页面.我相信这意味着授权正常工作,因为这使它像生成的示例代码一样.
但是,如果我取消评论insert和使用resumable=True媒体机构,我得到:
ResumableUploadError: Failed to retrieve starting URI.
Run Code Online (Sandbox Code Playgroud)
如果我使用resumable=False,我得到:
HttpError: <HttpError 401 when requesting https://www.googleapis.com/upload/drive/v2/files?uploadType=multipart&alt=json returned "Login Required">
Run Code Online (Sandbox Code Playgroud)
所以我似乎能够通过OAuth 2.0授权,但无法插入文件.
请尝试我们的快速入门应用程序: https ://developers.google.com/api-client-library/python/start/installation
您可以创建一个快速启动应用程序引擎应用程序,这对于您创建初始设置很有用。有关具体用例,请参阅驱动器 API 参考。
| 归档时间: |
|
| 查看次数: |
5308 次 |
| 最近记录: |