I’m new to Firebase and I’m trying to send a body using the Firebase FCM. (I’m doing a personal project similar to Whatsapp)
I’m using a Expo React-native project. Currently I’m testing using the Expo App on both physical phones (Galaxy S10e sending to GalaxyS23).
I looked everywhere to find an answer but I’m weeks stuck in this part.
The react-native code:
export const requestFirebase = async (): Promise<any> => {
const headers: {[key: string]: string} = {};
headers['Content-Type'] = 'application/json';
const jwttoken = 'token that I got using gcloud auth application-default print-access-token';
headers['Authorization'] = "Bearer " + jwttoken;
const body = JSON.stringify({
message: {
token: 'token that I got using Notifications.getDevicePushTokenAsync() on another device',
notification: {
body: "This is an FCM notification message!",
title: "FCM Message"
}
}
});
try {
const init = { headers, method: 'POST', body};
log.dev('headers', init);
const response = await fetch('https://fcm.googleapis.com/v1/projects/ProjectCodeFromFirebase/messages:send', init);
log.dev('response', response);
return response;
}
catch (error: any){
log.err(error);
return undefined;
}
}
The response:
LOG [DEV] [response] {
"type": "default",
"status": 403,
"ok": false,
"statusText": "",
"headers": {
"map": {
"alt-svc": "h3=":443"; ma=2592000,h3-29=":443"; ma=2592000",
"cache-control": "private",
"content-type": "application/json; charset=UTF-8",
"date": "Fri, 07 Jun 2024 13:54:22 GMT",
"server": "scaffolding on HTTPServer2",
"vary": "Origin, X-Origin, Referer",
"x-content-type-options": "nosniff",
"x-frame-options": "SAMEORIGIN",
"x-xss-protection": "0"
}
},
"url": "https://fcm.googleapis.com/v1/projects/languagechat-8e41c/messages:send",
"bodyUsed": false,
"_bodyInit": {
"_data": {
"size": 262,
"offset": 0,
"blobId": "71025cce-316a-45c4-a323-be52f4194ab8",
"__collector": {}
}
},
"_bodyBlob": {
"_data": {
"size": 262,
"offset": 0,
"blobId": "71025cce-316a-45c4-a323-be52f4194ab8",
"__collector": {}
}
}
}
In the firebase console the value of request do increase every time I try.
My V1 is active:
I also tried using Postman but the response was strange so I gave up.
<title>Error 404 (Not Found)!!1</title>
I expected to receive a 200. Because I have another device trying to receive the message.