0
我使用的離子2離子2 FCM推送通知
我安裝了插件
HTTP.post to FCM Server not working
cordova plugin add cordova-plugin-fcm
這裏是我的代碼
import { Http, Headers } from '@angular/http';
someKey;
t;
constructor(public http: Http) {
this.t="cwJHK1Ma-Mo:APA91bFRpBudeF9QhTosUs6-N7sSEW3D104cUO3M6gHFyTTDEodTWL5VVMbbbvqbhb5zkgRZwkIMC4p7PYbG7Pmfo6vb4IFB50ZTJN0W-2iJoJ-ZUdeBtcvjJ2nImflgUgtNplA210HP"
this.someKey="AAAAbZuUvR8:APA91bF3-tKjl5FmXx...."
let url = 'https://fcm.googleapis.com/fcm/send';
let body =
{
"notification": {
"title": "Notification title",
"body": "Notification body",
"sound": "default",
"click_action": "FCM_PLUGIN_ACTIVITY",
"icon": "fcm_push_icon"
},
"data": {
"hello": "This is a Firebase Cloud Messagin hbhj g Device Gr new v Message!",
},
"to": this.t
};
let headers: Headers = new Headers({
'Content-Type': 'application/json',
'Authorization': 'key='+this.someKey
});
let options = new RequestOptions({ headers: headers });
console.log(JSON.stringify(headers));
this.http.post(url, body, headers).map(response => {
return response;
}).subscribe(data => {
//post doesn't fire if it doesn't get subscribed to
console.log(data);
});
}
但我得到這個犯錯
控制檯告訴錯誤是請求缺少一個認證密鑰(FCM令牌)。請參閱firebase.google.com/docs/cloud-messaging/server上的FCM文檔「身份驗證」部分。錯誤401
EXCEPTION: Response with status: 401 OK for URL: https://fcm.googleapis.com/fcm/send
我該如何解決此問題。
請告訴我,
謝謝。