【发布时间】:2018-06-25 18:39:46
【问题描述】:
我已将我的网络应用设置为接收 Firebase 云消息,但为了发送它们,我知道我需要一个 OAuth2.0 令牌,它是从我的服务帐户私钥生成的。我已经下载了密钥并安装了适用于 Python 的 Google API 客户端库。这是我的代码:
from oauth2client import *
def _get_access_token():
"""Retrieve a valid access token that can be used to authorize requests.
:return: Access token.
"""
credentials = ServiceAccountCredentials.from_json_keyfile_name(
'service-account.json', FCM_SCOPE)
access_token_info = credentials.get_access_token()
return access_token_info.access_token
_get_access_token()
当我运行它时,我得到了
Traceback (most recent call last):
File "get-oauth-token.py", line 11, in <module>
_get_access_token()
File "get-oauth-token.py", line 7, in _get_access_token
credentials = ServiceAccountCredentials.from_json_keyfile_name(
NameError: name 'ServiceAccountCredentials' is not defined
我假设我错过了一个导入,但我不确定是什么。
【问题讨论】:
-
from oauth2client.service_account import ServiceAccountCredentials但FCM_SCOPE我不知道
标签: python firebase oauth-2.0 firebase-cloud-messaging