首页 文章

如何在Google Cloud 端硬盘和App Engine SDK中使用Oauth2服务帐户

提问于
浏览
3

使用App Engine和服务帐户访问Google Cloud 端硬盘的工作正常 . 为了使其工作,我还必须与服务帐户名称共享我的驱动器文件:appid@appspot.gserviceaccount.com .

但是当我使用GAE SDK时,我会收到401.我认为原因是我的共享SDK的service_account名称 . SDK的服务帐户名称为:test @ localhost,具体取决于:

app_identity.get_service_account_name()  # returns test@localhost

SDK控制台中的错误消息:

发生错误:https://www.googleapis.com/drive/v2/files/0B9-mE....................nM/children?alt = json&key = AI ........................ N0返回“证书无效”>

这是访问Google Cloud 端硬盘的代码:

def get(self):

    SCOPE = 'https://www.googleapis.com/auth/drive'
    credentials = AppAssertionCredentials(scope=SCOPE)
    logging.info(app_identity.get_service_account_name())
    http = credentials.authorize(httplib2.Http())
    if os.environ['SERVER_SOFTWARE'].startswith('Development') : 
        service = build('drive', 'v2', http=http, developerKey='...API key...')
    else :
        service = build('drive', 'v2', http=http, developerKey='...APY key...')
    # drive requests

UPDATE :

我的个人意见:这只适用于GAE而不适用于SDK,因为我无法使用SDK service_account名称创建 Cloud 分享 . 或者是否可以指定另一个服务帐户名称 .

1 回答

相关问题