i wanted to add the updated version (
FCM APIs to HTTP v1 ) of fcm api which is like this
headers = {
"Authorization": "Bearer " + _get_access_token(),
"Content-Type": "application/json; UTF-8"
}
response = requests.post(
"https://fcm.googleapis.com/v1/projects/my_project_id/messages:send",
data=json.dumps(message),
headers=headers
here is code which i have included to get the access token
def _get_access_token():
"""Retrieve a valid access token that can be used to authorize requests.
:return: Access token.
"""
credentials = service_account.Credentials.from_service_account_file(
'service_account_key.json', scopes=SCOPES)
request = google.auth.transport.requests.Request()
credentials.refresh(request)
return credentials.token
print(_get_access_token())
I have added the service account json to same directory
service_account_key.json
directory look like this
module |-- models | |-- service_account_key.json
|-- |---get_token_from_key.py | |-- __init__.py |-- other_module_files..
i,m getting this error
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/odoo/modules/_service_account_info.py", line 78, in from_filename
with io.open(filename, "r", encoding="utf-8") as json_file:
FileNotFoundError: [Errno 2] No such file or directory: 'service_account_key.json'