I am trying to make a topic subscription to expo server
const triggerNotificationHandler = () => {
fetch('https://exp.host/--/api/v2/push/send', {
method: 'POST',
headers: {
Accept: 'application/json',
'Accept-Encoding': 'gzip, deflate',
'Content-Type': 'application/json',
},
body: JSON.stringify({
to: pushToken,
data: { extraData: 'Some data' },
title: 'Sent via the app',
body: 'This push notification was sent via the app!',
}),
});
};
Is it possible to make a topic subscription and send notification to user using expo server
i want to send it to a group of people what should i do ?
Expo doesn't currently have support for topic subscription and broadcast. The alternative you have for now is to broadcast to all the user tokens. Or you can eject your Expo app and use firebase messaging that support topic broadcasting.
Related
I installed jwt plugin and I configured jwt token to access WordPress rest API, when I use postman everything is good and I can have a successful post request but when I post data using axios in vuejs I get this error
response: "{\"code\":\"rest_cannot_create_user\",\"message\":\"Sorry, you are not allowed to create new users.\",\"data\":{\"status\":401}}"
below code is my post request in my app:
Register() {
const data = JSON.stringify({
name: this.username,
username: this.username,
email: this.email,
password: this.password,
roles: ['editor'],
});
axios
.post('http://localhost/wp-json/wp/v2/users', data, {
headers: {
Authorization:
'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOjEsIm5hbWUiOiJQZWRyYW0iLCJpYXQiOjE2NTQ1MTY4MDgsImV4cCI6MTgxMjE5NjgwOH0.0NoZwWpMMDw0_5xd3anIEKq_djwdV3vqbGMw_UeSvYI',
'Content-Type': 'application/json',
},
})
.then((response) => {
console.log(response);
})
.catch((error) => {
console.log(error);
});
},
also when I use the code in nodejs in the backend application everything works fine.
I am new to react native and I am stuck to send push notification from client side. i have FCM token of every user but need to send a notification to specific user. if you want more clarity please comment and let me know the solution of this
I saw your problem and I have a solution for you. I am already doing it and here's my code.
export const sendPushNotification = async (token, title, body,) => {
//console.log("token==>", token);
const FIREBASE_API_KEY ="<your firebase cloud messaging server key>"
const message = {
registration_ids: [token],
notification: {
title: title,
body: body,
vibrate: 1,
sound: 1,
show_in_foreground: true,
priority: "high",
content_available: true
},
};
let headers = new Headers({
"Content-Type": "application/json",
Authorization: "key=" + FIREBASE_API_KEY
});
let response = await fetch("https://fcm.googleapis.com/fcm/send", {
method: "POST",
headers,
body: JSON.stringify(message)
});
// console.log("=><*", response);
response = await response.json();
// console.log("=><*", response);
};
you can use this function like this
sendPushNotification(
FCMToken,
'title of message',
`this is body of message`,
);
hope it will worked on your side
Currently I have topics to send push notifications. In particular
all: this is a topic in which I send notifications to everyone
paid: this is a topic in which I send notification only to a small group of users
Today I was upgrading Flutter to the newest firebase package and I encountered this:
<String, dynamic>{
'notification': <String, dynamic>{
'body': 'this is a body',
'title': 'this is a title'
},
'priority': 'high',
'data': <String, dynamic>{
'click_action': 'FLUTTER_NOTIFICATION_CLICK',
'id': '1',
'status': 'done'
},
'to': await firebaseMessaging.getToken(),
},
But wait, isn't 'to' meant to send notifications only to a specific device? Why does
'to': await firebaseMessaging.getToken(),
this send a message to all devices? I am confused because the doc says that 'to' is for specific targets too. Thanks!
The to property in an FCM message determines where it is sent to. The value of the to property can be the device token of a single device, it can be the ID of a device group, or it can be a topic.
It sounds like in your actual code you pass a topic in to, while in the sample in your question it passes a device token.
you can use this Firestore api by google to send push notifications
Future<bool> callOnFcmApiSendPushNotifications(List <String> userToken) async
{
final postUrl = 'https://fcm.googleapis.com/fcm/send';
final data = {
"registration_ids" : userToken,
"collapse_key" : "type_a",
"notification" : {
"title": 'NewTextTitle',
"body" : 'NewTextBody',
}
};
final headers = {
'content-type': 'application/json',
'Authorization': constant.firebaseTokenAPIFCM // 'key=YOUR_SERVER_KEY'
};
final response = await http.post(postUrl,
body: json.encode(data),
encoding: Encoding.getByName('utf-8'),
headers: headers);
if (response.statusCode == 200) {
// on success do sth
print('test ok push CFM');
return true;
} else {
print(' CFM error');
// on failure do sth
return false;
}
}
I am building a react-native app on expo. The app uses Google Drive APIs to create and write into Spreadsheets.
I use firebase to keep track of the spreadsheet Id and similar info in a database.
I would like to automatically ask for a new access token with the refresh token once the first has expired.
Looking at the docs I put together this HTTP call but it returns a 401 Unauthorized error...
async function getNewToken(refreshToken) {
return await fetch('https://oauth2.googleapis.com/token', {
method: 'post',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
client_id: '<MY_CLIENT_ID>',
client_secret: '<MY_CLIENT_SECRET>',
refresh_token: refreshToken,
grant_type: 'refresh_token',
}),
});
}
What am I getting wrong?
Thanks in advance
So I able to successfully send a request via postman, but whenever I throw it into fetch I get back a 401 error.
export const createUser = () => {
return async (dispatch) => {
dispatch({ type: CREATE_USER });
console.log('we are in the create user function');
try {
let response = await fetch('secret.com/v1/login/signup', {
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({
email: 'test1231273123#test.com',
password: 'Asadasd123123',
first_name: 'joe',
last_name: 'doe',
phone_number: '373738'
})
});
console.log('response ' + JSON.stringify(response));
} catch (error) {
console.log(error);
}
};
};
Here is the error I keep receiving.
response {"type":"default","status":401,"ok":false,"headers":{"map":{"access-control-allow-methods":["GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS"],"access-control-allow-origin":["*"],"connection":["keep-alive"],"access-control-allow-credentials":["true"],"content-length":["188"],"content-type":["text/html; charset=utf-8"],"access-control-allow-headers":["Content-Type, Accept, Authorization"],"www-authenticate":["Basic realm=\"Restricted\""],"date":["Thu, 12 Jan 2017 16:57:58 GMT"],"server":["nginx"]}},"url":"https://secret.com/v1/login/signup","_bodyInit":{},"_bodyBlob":{}}
My backend developer believes I ran into a cross domain issue and need to setup a proxy server? "set up some proxy server (I would recommend nginx) that would proxy ajax queries to our API domain"
I think it has something to do with fetch? Ideas?
I believe you need to provide the protocol, change:
await fetch('secret.com/v1/login/signup'...
to
await fetch('http://secret.com/v1/login/signup'