我正在使用离子2
我安装了插件
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
我该如何解决此问题。
请建议我,
谢谢。
嘿,我使用https://firebase.google.com/docs/cloud-messaging/admin/send-messages,这很容易,您不必手动处理请求。