从Google App Engine访问Firebase数据库

时间:2017-04-07 02:35:00

标签: python google-app-engine firebase firebase-realtime-database

我无法从GAE应用访问Firebase数据库。它在本地运行时工作正常,但部署到GAE(* .appspot.com)我从Firebase收到了未经授权的错误。可能有一些我错过的显而易见的事情......

这是我使用的_get_http()函数。它工作正常(在gcloud beta auth application-default login之后)

def _get_http():
    _FIREBASE_SCOPES = [
    'https://www.googleapis.com/auth/firebase.database',
    #'https://www.googleapis.com/auth/userinfo.email'
    ]

    """Provides an authed http object."""
    http = httplib2.Http()

    # Use application default credentials to make the Firebase calls
    # https://firebase.google.com/docs/reference/rest/database/user-auth
    creds = GoogleCredentials.get_application_default().create_scoped(_FIREBASE_SCOPES)

    creds.authorize(http)

    return http

我从Firebase返回的错误是:

{u'error': u'Unauthorized request.'}

来自GAE的日志包括:

11:14:43.835
Attempting refresh to obtain initial access_token
11:14:44.625
Refreshing due to a 401 (attempt 1/2)
11:14:44.966
Refreshing due to a 401 (attempt 2/2)

1 个答案:

答案 0 :(得分:1)

知道了!我已经评论'https://www.googleapis.com/auth/userinfo.email'认为这是不必要的。错误。再次启用它,宾果!