Firebase Cloud Messaging topic send, message does not show in Notifications and is never sent - firebase-cloud-messaging

I am using the REST api and I am trying to send to a topic. I know the topic exists because I can see in the Notification console that the topic is there. And I can send a test message through the console and that works.
However, when I use the REST api, I get an http status 200 response with json {"message_id":8769790390495267408} which looks like a successful send. However, the message does not show up in Notifications and the message is not sent to subscribed clients.
My message looks like, which is from the docs
https://fcm.googleapis.com/fcm/send
Content-Type:application/json
Authorization:key=AIzaSyZ-1u...0GBYzPu7Udno5aA
{
"to": "/topics/foo-bar",
"data": {
"message": "This is a Firebase Cloud Messaging Topic Message!",
}
}
And I am using the "Server key" and not the Web api key.
Thanks for any help.

For iOS, try using notification instead of data. Then add in the priority and set it to high. The payload should look something like this:
https://fcm.googleapis.com/fcm/send
Content-Type:application/json
Authorization:key=AIzaSyZ-1u...0GBYzPu7Udno5aA
{
"to": "/topics/foo-bar",
"priority": "high",
"notification" : {
"body" : "great match!",
"title" : "Portugal vs. Denmark",
"icon" : "myicon"
}
}

Related

How do I fix the problem behind "THIRD_PARTY_AUTH_ERROR" when using Google's API Explorer to send a Firebase Cloud Messaging message?

I am trying to create a very simple Web app that can send and receive messages (including Push notifications) via Firebase Cloud Messaging. I want to try testing the ability to receive test messages sent from the Google API Explorer. However, I am running into a curious error as just about any API call from the relevant API URL will return the following error:
{
"error": {
"code": 401,
"message": "Auth error from APNS or Web Push Service",
"status": "UNAUTHENTICATED",
"details": [
{
"#type": "type.googleapis.com/google.firebase.fcm.v1.FcmError",
"errorCode": "THIRD_PARTY_AUTH_ERROR"
}
]
}
}
For reference, here is the message that I am trying to send:
{
"message": {
"token": "[FCM_TOKEN]",
"notification": {
"title": "New Notification",
"body": "Sample Text"
}
}
}
I also note that when I add "validate_only": true to the message, that the error goes away and the send request succeeds (though this is of no help, as that disables actually sending the message).
I am stumped, becuse the hint that pops up suggests that my OAuth2 credentials are invalid, though I leave the OAuth2 credential option checked and go through the authorization popup to provide my credentials.
Are you running the web app on Firefox, perhaps?
I have been running around my tail with this same issue for days now, and today I've found that there is an issue on Firefox, while this does work on Chrome:
Similar stack overflow question
The issue on the Firebase repository on Github
Although not a proper answer, I hope this helps.

kucoin websocket api, how to "subscribe" to their public channel, they say no authorization required, but they ask for a token :(

The question is about kucoin websocket public channel (not trades) just last trades
I just want a live feed of trades like other crypto exchanges...
but when I want to connect to "wss://ws-api-futures.kucoin.com/endpoint" I get WebSocketError: Received unexpected status code (401 Unauthorized)
the documentation https://docs.kucoin.com/futures/#create-connection lack explications :(
normally with other exchanges I can just do this in javascript
bybit_market_ws = new WebSocket("wss://stream.bybit.com/spot/quote/ws/v2");
bybit_market_ws.onmessage = event => bybit_trades(event.data);
bybit_market_ws.onopen = event => bybit_market_ws.send(JSON.stringify({"topic":"trade","params":{"symbol":"BTCUSDT","binary":false},"event":"sub"}));
function bybit_trades (jsonx) { console.log(JSON.parse(jsonx)); }
so how can I do that with kucoin websocket ?
according to the documentation i would need a "public token"...
but there is no explication on how to get that token :(
does someone knows how I would retrieve the last trades via websocket (public) channel ?
Note that the following steps may be changed when the API is updated.
All information can be found at https://docs.kucoin.com/#apply-connect-token
Get the public token
Send a empty http POST (GET will not work) message to https://api.kucoin.com/api/v1/bullet-public.
Response:
{
"code": "200000",
"data": {
"token": "2neAiuYvAU61ZD...",
"instanceServers": [
{
"endpoint": "wss://ws-api.kucoin.com/endpoint",
"encrypt": true,
"protocol": "websocket",
"pingInterval": 18000,
"pingTimeout": 10000
}
]
}
}
Connect to the Websocket
With the data of the repsonse above:
websocket: endpoint + "?token=" + token
Example: wss://ws-api.kucoin.com/endpoint?token=2neAiu....
Get all supported trading pairs
send a http GET message to https://api.kucoin.com/api/v1/symbols
{
"code": "200000",
"data": [
{
"symbol": "REQ-ETH",
"name": "REQ-ETH",
"baseCurrency": "REQ",
"quoteCurrency": "ETH",
...
},
{
"symbol": "BTC-USDC",
"name": "BTC-USDC",
"baseCurrency": "BTC",
"quoteCurrency": "USDC",
...
},
...
Get trading data
When the websocket connection is established send a http POST message:
{
"type": "subscribe", //subscribe or unsubscribe
"topic": "/market/ticker:BTC-USDT,BTC-USDC"
}
maybe this answer will not please you at all, but i will try, most of the people who work from the API in KuCoin do it with python, in fact the SDK for Nodejs is out of date, your best bet is to ask in the telegram channel https://t.me/KuCoin_API, there are KuCoin engineers who always help, although most of them use python, there is also the academy channel https://t.me/kucoin_learning, where there are examples, in short I can only mention references because I was also where you are, and the best I could do was that and review the SDk code and from there intuit and create my own adjustments
PD: the datafeed.js file is your best option, check it out https://github.com/Kucoin/kucoin-futures-node-sdk/blob/master/src/lib/datafeed.js

FCM API returns a success response but push notification is not delivered to user

I am sending push notification using FCM legacy API and by request looks like the following
POST https://fcm.googleapis.com/fcm/send
{
"to" : "USER-DEVICE-TOKEN",
"collapse_key" : "type_a",
"priority" : "high",
"notification" : {
"body" : "Getting this?",
"title": "Let me know if you got this message",
"icon": "ic_launcher"
},
"data": {
"one": "two"
}
}
This request returns the following response
{
"multicast_id": 144107415xxxxxxxxx,
"success": 1,
"failure": 0,
"canonical_ids": 0,
"results": [
{
"message_id": "0:1581xxxxx5%32xxxxxxxxx"
}
]
}
But the user never receives any push notification. This happens for most of the user but about 10% of total user does receive push notification send by the same mechanism. I am out of sorts regarding this, I don't know whats going on or even how to go about debugging this. Has anyone run into this issue? The app is written in React Native and uses invertase/react-native-firebase for firebase features. Thanks

Twitter Insights API with Postman

I'm trying to read insights of my Twitter account with Twitter Insights API and when I request to that given end point I get and error called :
{
"errors": [
{
"code": "UNAUTHORIZED_ACCESS",
"message": "This request is not properly authenticated"
}
],
"request": {
"params": {}
}
}
This is the end point I tried :
https://ads-api.twitter.com/2/insights/accounts/:account_id/available_audiences
I used the given credentials like Consumer Key, Secret and Token, Token secret.
Can anyone explain me why I'm getting this error ? And what I should do ?
Here is a screenshot
Header:
You have to check box "Add params to header"
Everything else should be ok. Just check Consumer Key, Consumer Secret,... data

GCM Unauthorized Error 401

I'm not able to get response from GCM even i'm providing correct server API key generated by google.
Problem : I want to make a push notification using GCM from my sails app.
I'm posting below code to "https://android.googleapis.com/gcm/send"
Code : 1
{
"headers":{
"Content-Type":"application/json",
"Authorization":"key=xxxxxxxxxxxxxxxxxxxx"
},
"notification":{
"title":"Hello Notify",
"text":"Notification By Sails"
},
"registration_ids":["xxxxxxxxxxxx","xxxxxxxxxxxx","xxxxxxxxxxxx"]
}
Code : 2
{
"headers":{
"Content-Type":"application/json",
"Authorization":"key=xxxxxxxxxxxxxxxxxxxx"
},
"body":{
"notification":{
"title":"Hello Notify",
"text":"Notification By Sails"
}
},
"registration_ids":["xxxxxxxxxxxx","xxxxxxxxxxxx","xxxxxxxxxxxx"]
}
I'm getting response as below.
"statusCode": 401,
"body": "<HTML>\n
<HEAD>\n<TITLE>Unauthorized</TITLE>\n</HEAD>\n
<BODY BGCOLOR=\"#FFFFFF\" TEXT=\"#000000\">\n
<H1>Unauthorized</H1>\n
<H2>Error 401</H2>\n
</BODY>\n
</HTML>\n",
The headers should be HTTP headers, not element in the payload.
Make sure you have enabled the right API in Cloud Console. If sending with a Server API key, you need to have "Google Cloud Messaging for Android" enabled.