我已经设置了我的网络应用程序以接收Firebase Cloud Messages,但为了发送它们,我理解我需要一个OAuth2.0令牌,该令牌是从我的服务帐户私钥生成的。我已经下载并安装了Google API Client Library for Python中的密钥。这是我的代码:
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
我猜测是缺少了某个import,但具体是哪个我不确定。
FCM_SCOPE
我不知道。 - jiamo