【发布时间】:2013-08-12 16:55:38
【问题描述】:
我正在尝试获得对 Google Drive API 的服务帐户访问权限。我在构建应用程序时遵循了Google Drive SDK example。我的代码与示例几乎完全一样:
class MainPage(webapp2.RequestHandler):
def get(self):
build = createDriveService(user)
searchFile = build.files().get(fileId='FILEID').execute()
self.response.write(searchFile)
def createDriveService(userEmail):
API_KEY = 'APIKEY'
credentials = AppAssertionCredentials(
scope='https://www.googleapis.com/auth/drive',
sub=userEmail)
http = httplib2.Http()
http = credentials.authorize(http)
return build('drive', 'v2', http=http, developerKey=API_KEY)
当我调用访问我的 GAE 页面时,我得到的日志中的错误是:
<"File not found: FILEID">
我知道文件 ID 存在,因为我从 UI 复制了它。我正在对变量 API_KEY 使用简单的密钥访问。我应该以不同的方式验证我的申请吗?
EDIT1:
我尝试过关注其他各种 StackOverflow。其中之一涉及使用 SignedJwtAssertionCredentials 并将 .p12 密钥转换为 .pem 密钥。在这个改变之后,我得到了一个
cannot import SignedJwtAsserionCredentials
错误。从那里我确保将 pycrypto 库包含在我的app.yaml 中。有什么想法吗?
EDIT2
我已成功在应用引擎上模拟用户。我关注了this 之前回答的问题,并且成功了。
【问题讨论】:
-
关键信息是我的“子”参数。谢谢!
标签: python google-app-engine google-drive-api google-api-python-client