Unknown name "time_to_live" at 'message': - node.js

I am trying to send push notification via firebase:
await admin.messaging().sendAll({
token: 'some token',
data: {val1: '1', val2: '2'},
time_to_live: 300,
});
I am getting next error:
{"message":"Send push notification failed, Invalid JSON payload
received. Unknown name "time_to_live" at 'message': Cannot find
field.","level":"error"}

In firebase for time_to_live the key is ttl, also I use this request body for sending push notifications in android apps:
const body = {
notification: {
title: 'xxxx',
body: "xxxxxxxx"
},
data: {
notification_message: "xxxxxx"
},
token: 'xxxxxx',
android: {
ttl: 3600,
notification: { icon: 'xxxxx', color: '#b2b2b2' }
}
}
await admin.messaging().send(body)
Use ttl key in case of time_to_live.

Related

FCM notification not sent with messaging.sendAll() function - NodeJS

I'm trying to send multiple notifications using the messaging.sendAll() function of the Firebase Admin SDK.
The way in which I write the messages to send is this:
const messages = [];
const token2 = user2Data.notificationToken;
messages.push({
notification: {
title: `title`,
body: "this is the body!",
icon: "default",
sound: "customNotificationSound.wav",
content_available: "true",
},
data: {
notificationType: "notif2",
uid1: toUser,
uid2: fromUser,
},
token: token2,
});
const token1 = user1Data.notificationToken;
messages.push({
notification: {
title: `title`,
body: "this is the body!",
icon: "default",
sound: "customNotificationSound.wav",
content_available: "true",
},
data: {
notificationType: "notif1",
uid1: toUser,
uid2: fromUser,
},
token: token1,
});
return admin.messaging().sendAll(messages).then((promMes) => {
console.log("messages are sent");
console.log(promMes);
});
I don't know why but the messages to the different devices have not been sent.
I know that because of the promise I receive after I call the method sendAll(). In fact the error I get in the log is this:
textPayload: " { success: false, error: [FirebaseMessagingError] },"
I suppose that the problem hides behind how I construct the message payload but I wouldn't know how to fix it.

Angular Http POST change format value

I am sending the object message to an API by using POST request on Angular :
//Angular
var message = {
'title':"Test",
'content':"blabla",
'image':"none",
'author':"michael",
'likedBy':['alexis','laura']
};
return this.http.post(this.REST_API_SERVER, message, {headers: new HttpHeaders({'Content-Type': 'application/x-www-form-urlencoded'})});
Actually my API output show me this :
OUTPUT:
{
'{"title":"Test","content":"blabla","image":"none","author":"michael","likedBy":': { '"alexis","laura"': '' }
}
But I would like this :
{
_id: 5f887c43bee87a1014d89d21,
title: 'Test',
content: 'blabla',
image: 'none',
author: 'michael',
likedBy: [ 'alexis', 'laura' ]
}
You need to change content type to application/json.

Missing credentials while calling YouTube insert API

I want to use API key instead of OAuth token to call insert API from YouTube v3 lib. Code snippet is like below:
await google
.youtube("v3")
.videos.insert({
key: "my-youtube-api-key",
part: "id,snippet,status",
notifySubscribers: false,
requestBody: {
snippet: {
title: "Test video title",
description: "Test video description",
},
status: {
privacyStatus: "public",
},
},
media: {
body: fs.createReadStream(filePath),
},
})
.catch((err) => {
console.log("Upload to YouTube failed", err);
return null;
});
However, I am hitting error code 401, message is:
code: 401,
errors: [
{
message: 'Login Required.',
domain: 'global',
reason: 'required',
location: 'Authorization',
debugInfo: 'Authentication error: missing credentials.',
locationType: 'header'
}
]
How can I fix this issue? Isn't API key not supported? Thanks!
As per the docs, it's insufficient to use an API key on Videos.insert endpoint; you'll have to be properly authorized to call this endpoint:
Authorization
This request requires authorization with at least one of the following scopes (read more about authentication and authorization).
Scope
https://www.googleapis.com/auth/youtube.upload
https://www.googleapis.com/auth/youtube
https://www.googleapis.com/auth/youtubepartner
https://www.googleapis.com/auth/youtube.force-ssl

Firebase Auth REST API: OAuth sign-in with Twitter gives error 32 "could not authenticate you"

I'm writing a function in Node.js to log a user into Firebase using Twitter credentials, via the REST API (requests are made using the request library). I'm able to use the Twitter credentials to post a tweet, but attempting to sign in to Firebase with /accounts:signInWithIdp is returning the following error:
{ error:
{ code: 400,
message: 'INVALID_IDP_RESPONSE : Failed to fetch resource from https://api.twitter.com/1.1/account/verify_credentials.json?include_email=true, http status: 401, http response: {"errors":[{"code":32,"message":"Could not authenticate you."}]}',
errors: [ [Object] ] } }
This is my code:
loginWithOAuth = (idToken, postBody, onCompletion, onError) => {
var form = {
postBody: querystring.stringify(postBody),
requestUri: 'request uri',
returnIdpCredential: 'false',
returnSecureToken: 'true',
}
request.post({
url: 'https://identitytoolkit.googleapis.com/v1/accounts:signInWithIdp?key=' + firebase_api_key,
body: form,
json: true
}, (error, r, body) => {
// ...
});
}
where postBody is of the form
{
access_token: 'token',
oauth_token_secret: 'token secret',
providerId: 'twitter.com'
}
My Twitter app has permission to access user emails. I've also whitelisted the requestUri in both Firebase and Twitter. Regenerating my app & user keys doesn't make a difference.
What am I missing?
postBody is not a stringified object, it is URL encoded:
var form = {
postBody: 'access_token=[TWITTER_ACCESS_TOKEN]&oauth_token_secret=[TWITTER_TOKEN_SECRET]&providerId=twitter.com',
requestUri: 'request uri',
returnIdpCredential: 'false',
returnSecureToken: 'true',
}

How can i send custom data along with push notification?

i have one use case in which I need to send custom data along with push notification in Google Assistant using ActionOnSDK , how can I send it anyone has any clue?
let notification = {
userNotification: {
title: 'A new tip is added',
},
target: {
userId: 'abcd1234-EFGH_789',
intent: 'tell_latest_tip',
// Expects a IETF BCP-47 language code (i.e. en-US)
locale: 'en-US'
},
};
request.post('https://actions.googleapis.com/v2/conversations:send', {
'auth': {
'bearer': tokens.access_token,
},
'json': true,
'body': {
'customPushMessage': notification
}
};

Resources