我开发了一个Flutter应用程序,该应用程序每次更新数据库时都会收到通知。
使用Angular分别处理数据库。但是,当我从angular到firebase发出POST请求以发送通知时,记录响应时出现以下错误:
这是代码:
export class AppComponent {
constructor(private CustomService: CustomService) {}
onButtonClick() {
this.CustomService.pushNotification().subscribe((Response) => {
console.log(Response);
});
}
}
这是服务代码:
export class CustomService{
// I also do not know if this is the correct format to send
myNotification: Object = {
notification: {
title: 'Angualr Notification',
body: 'Displayed from Angular: App is in backgroud or closed!',
},
data: {
title: 'Angular Notification',
body: 'Displayed From Angular: App is open',
click_action: 'FLUTTER_NOTIFICATION_CLICK',
},
topic: 'all_users',
};
FirebaseProjectURL: string "https://console.firebase.google.com/project/dummy-project-123/";
pushNotification(): Observable<Object> {
return this.http.post<Object>(this.FirebaseProjectURL, this.myNotification);
}
}
因此,经过大量搜索之后,我应该做的是:
export class MyCrudService {
// Request Body
myNotification: Object = {
condition: "('all_users' in topics)",
notification: {
title: 'Notification title',
body: 'Notification message',
},
data: {
title: 'Notification title',
body: 'Displayed',
click_action: 'FLUTTER_NOTIFICATION_CLICK',
},
};
// Request URL and Header
FirebaseProjectURL: string = 'https://fcm.googleapis.com/fcm/send';
headers: HttpHeaders = new HttpHeaders({
'Content-Type': 'application/json',
Authorization:'key=AAAA7k...5mHaW', // The full Server key
});
options = { headers: this.headers };
pushNotification(): Observable<Object> {
return this.http.post<Object>(
this.FirebaseProjectURL,
this.myNotification,
this.options
);
}
}
我在互联网上碰巧遇到了“ myNotification”,但在文档中找不到有关POST请求正文的任何内容。
如果有人在myNotification可能的“键”上有一个链接,我将不胜感激。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句