2017-04-07 134 views
0

我無法從GAE應用訪問Firebase數據庫。在本地運行時可以正常工作,但已部署到GAE(* .appspot.com)我從Firebase獲得未經授權的錯誤。有可能是我錯過了一些明顯的事情...從Google App Engine訪問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 

我回來從火力地堡的錯誤是:

{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

明白了!我已經注意到'https://www.googleapis.com/auth/userinfo.email'認爲這是不必要的。錯誤。再次啓用它,賓果!