では動作しません。これは私がデプロイした後で動作しますが、ローカルでは動作しません。Firebase ApplicationDefaultCredentialsは、私が上の指示に従っててるdev_appserver
私はgcloud auth application-default login
を実行してきたし、次のように私の資格情報を設定している:
try:
from functools import lru_cache
except ImportError:
from functools32 import lru_cache
import json
import httplib2
from oauth2client.client import GoogleCredentials
_FIREBASE_SCOPES = [
'https://www.googleapis.com/auth/firebase.database',
'https://www.googleapis.com/auth/userinfo.email']
# Memoize the authorized http, to avoid fetching new access tokens
@lru_cache()
def _get_http():
"""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
def firebase_put(path, value=None):
"""Writes data to Firebase.
An HTTP PUT writes an entire object at the given database path. Updates to
fields cannot be performed without overwriting the entire object
Args:
path - the url to the Firebase object to write.
value - a json string.
"""
response, content = _get_http().request(path, method='PUT', body=value)
return json.loads(content)
firebase_put()を呼び出す私は
{
"error" : "Permission denied."
}
を取得する不思議なそれだけでfirebaseように見えますそれは問題を抱えている。私は、dev_appserverのApplicationDefaultCredentialsを使用してクラウドの音声要求を正常に行うことができます。
資格情報がヘッダーに追加されていることを確認しました。
Header {
Key: "user-agent"
Value: "Python-httplib2/0.9.2 (gzip)"
}
Header {
Key: "accept-encoding"
Value: "gzip, deflate"
}
Header {
Key: "authorization"
Value: "Bearer REDACTED_FOR_PRIVACY"
}
Payload: "{\"sender\": \"12314\", \"timestamp\": 1478368765.042335, \"message\": \"asdf\"}"
FollowRedirects: false
Deadline: 5
MustValidateServerCertificate: true
私は間違っていますか?
この回答http://stackoverflow.com/a/22723127/2987899 – atimothee
@atimotheeをチェックアウト、私はその答えは、次の信じる右、効果的に既定の資格情報を使用するのと同じですか?または、デフォルトの資格情報が有効でない間に動作する理由がいくつかありますか? – astromme
これは何? http://stackoverflow.com/a/40493992/2987899 – atimothee