我试图在保存产品后发送推送通知,但按“保存”后,出现以下错误:
AuthenticationError at /register/ Please provide the api_key in the google-services.json file
Request Method: POST
Request URL: http://127.0.0.1:8000/register/
Django Version: 2.2.5
Exception Type: AuthenticationError
Exception Value:
请在google-services.json
文件中提供api_key
Exception Location: C:\Users\chida\AppData\Local\Programs\Python\Python37\lib\site-packages\pyfcm\baseapi.py in __init__, line 49
Python Executable: C:\Users\chida\AppData\Local\Programs\Python\Python37\python.exe
Python Version: 3.7.0
这是我基地的负责人:
<!-- The core Firebase JS SDK is always required and must be listed first -->
<script src="https://www.gstatic.com/firebasejs/3.9.0/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/3.9.0/firebase-messaging.js"></script>
<script>
// Your web app's Firebase configuration
var firebaseConfig = {
apiKey: "AIzaSyAaMtLcRqXU80pWdGLvh_1l43HIJ2Bn7ls",
authDomain: "frikiwaii-9a224.firebaseapp.com",
databaseURL: "https://frikiwaii-9a224.firebaseio.com",
projectId: "frikiwaii-9a224",
storageBucket: "frikiwaii-9a224.appspot.com",
messagingSenderId: "801502260469",
appId: "1:801502260469:web:634927965960d2963729bc"
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
let messaging = firebase.messaging();
navigator.serviceWorker
.register('./serviceworker.js')
.then(function(register) {
messaging.useServiceWorker(register);
messaging.requestPermission()
.then(function(){
console.log("The user has accepted the Notifications")
return messaging.getToken();
})
.then(function(token){
console.log(token);
fetch('save-token/',{
method:'post',
headers:{
'Content-Type':'application/json',
'Accept':'application/json'
},
body:JSON.stringify({
'token':token
})
})
.then(function(resultado){
console.log("Token saved")
})
.catch(function(e){
console.log("Error at trying to save Token")
})
})
.catch(function(e){
console.log("The user has not accepted the notifications")
})
})
messaging.onMessage(function(payload){
console.log("You have received a Notification")
let data = payload;
console.log(data);
let title = payload.notification.title;
let options = {
body: payload.notification.body,
icon: payload.notification.icon
}
let mensaje = new Notification(title, options);
});
</script>
这是baseapi.py
class BaseAPI(object):
"""
Base class for the pyfcm API wrapper for FCM
Attributes:
api_key (str): Firebase API key
proxy_dict (dict): use proxy (keys: `http`, `https`)
env (str): for example "app_engine"
json_encoder
"""
CONTENT_TYPE = "application/json"
FCM_END_POINT = "https://fcm.googleapis.com/fcm/send"
INFO_END_POINT = 'https://iid.googleapis.com/iid/info/'
api_key : "AIzaSyAaMtLcRqXU80pWdGLvh_1l43HIJ2Bn7ls"
# FCM only allows up to 1000 reg ids per bulk message.
FCM_MAX_RECIPIENTS = 1000
#: Indicates that the push message should be sent with low priority. Low
#: priority optimizes the client app's battery consumption, and should be used
#: unless immediate delivery is required. For messages with low priority, the
#: app may receive the message with unspecified delay.
FCM_LOW_PRIORITY = 'normal'
#: Indicates that the push message should be sent with a high priority. When a
#: message is sent with high priority, it is sent immediately, and the app can
#: wake a sleeping device and open a network connection to your server.
FCM_HIGH_PRIORITY = 'high'
# Number of times to retry calls to info endpoint
INFO_RETRIES = 3
def __init__(self, api_key=None, proxy_dict=None, env=None, json_encoder=None):
if api_key:
self._FCM_API_KEY = api_key
elif os.getenv('FCM_API_KEY', None):
self._FCM_API_KEY = os.getenv('FCM_API_KEY', None)
else:
raise AuthenticationError("Please provide the api_key in the google-services.json file")
self.FCM_REQ_PROXIES = None
self.requests_session = requests.Session()
retries = Retry(backoff_factor=1, status_forcelist=[502, 503, 504],
method_whitelist=(Retry.DEFAULT_METHOD_WHITELIST | frozenset(['POST'])))
self.requests_session.mount('http://', HTTPAdapter(max_retries=retries))
self.requests_session.mount('https://', HTTPAdapter(max_retries=retries))
self.requests_session.headers.update(self.request_headers())
self.requests_session.mount(self.INFO_END_POINT, HTTPAdapter(max_retries=self.INFO_RETRIES))
if proxy_dict and isinstance(proxy_dict, dict) and (('http' in proxy_dict) or ('https' in proxy_dict)):
self.FCM_REQ_PROXIES = proxy_dict
self.requests_session.proxies.update(proxy_dict)
self.send_request_responses = []
if env == 'app_engine':
try:
from requests_toolbelt.adapters import appengine
appengine.monkeypatch()
except ModuleNotFoundError:
pass
self.json_encoder = json_encoder
这是一个学校的项目,所以我真的希望有人能帮助我,谢谢你
目前没有回答
相关问题 更多 >
编程相关推荐