无法通过Google App Engine调用Google Apps脚本执行API

时间:2016-01-19 09:46:06

标签: python google-app-engine google-apps-script

简单地说,我按照本指南设置了“Google Apps脚本执行API”: https://developers.google.com/apps-script/guides/rest/quickstart/python

我可以使用我的客户端密码从本地Python程序调用Executable API,如指南中所述。没问题。

但我实际上想要使用相同的Google帐户从Google App Engine调用API。所以,我认为“服务帐户”可能是解决方案。

因此,我将创建凭证对象的方式更改为:

from oauth2client.appengine import AppAssertionCredentials

credentials = AppAssertionCredentials(
    'https://www.googleapis.com/auth/sqlservice.admin')

参考:developers.google.com / api-client-library / python / auth / service-accounts

但我的Google App Engine网络应用程序却抛出了这个错误:

INFO     2016-01-19 09:16:22,287 client.py:570] Attempting refresh to obtain initial access_token
WARNING  2016-01-19 09:16:22,297 urlfetch_stub.py:540] Stripped prohibited headers from URLFetch request: ['content-length']
{
  "error": {
    "code": 403,
    "message": "Project has not enabled the API. Please use Google Developers Console to activate the 'script' API for your project.",
    "errors": [
      {
        "message": "Project has not enabled the API. Please use Google Developers Console to activate the 'script' API for your project.",
        "domain": "global",
        "reason": "forbidden"
      }
    ],
    "status": "PERMISSION_DENIED"
  }
}

我已经在我的脚本项目和Google App Engine项目中启用了“Scripts Execution API”。有人可以帮忙吗?非常感谢

1 个答案:

答案 0 :(得分:0)

AppAssertionCredentials与已登录用户的App Engine上的用户凭据不同。这样,您只能访问分配给App Engine应用程序本身的帐户下存储的数据'。您链接到的Google Apps脚本执行API示例特别需要以真正的Google Apps用户身份访问数据。

在您的情况下,您可能希望将OAuth2DecoratorFromClientSecrets与您在本地使用的客户机密文件相同,但与App Engine应用程序一起上传。