step by step implementation of nativescript push notification in nativescript - firebase

can anyone give step by step guidence starting from creating a helloworld app then the remaining steps to do push notifications.
i have already gone through the below link and failed to achieve that
https://github.com/EddyVerbruggen/nativescript-plugin-firebase
i have some progress on it, refer below code.
http.request({
url: 'https://fcm.googleapis.com/fcm/send',
method: "POST",
headers: { 'Authorization': 'key=AIzaSyBri16HAa7g2REEy******YFnTDGIlM_1k', 'Content-Type': 'application/json' },
content: JSON.stringify({
"notification": {
"title": "testingtesting",
"text": "some text",
"sound": "default",
"click_action": "GENERAL",
"badge": "1",
"showWhenInForeground": true
},
"content_available": false,
"data": {
"foo": "bar"
},
"priority": "High",
'to': "AAAACcS8hG0:APA91bEonX87xRfBHvccNheOR2ppFHZKaFlGGm6PRF6eEEYZg5Gd7uU_OU0GRJ0MkiTrR2gSDGO7Nz6BByujX4ex1jGgKpO20SXcGMa78k405vNV_4uJ1UDk_b-0-regi5x96KRcaOMH"
})
}).then((response) => {
//HttpResult = response.content.toJSON();
console.log('----------------------------------------------------');
console.log(response);
}, (e) => {
console.log("Error occurred " + JSON.stringify(e));
});
},
the response is as below.
JS: ----------------------------------------------------
JS: {
JS: "content": {
JS: "multicast_id": 5720873045813109000,
JS: "success": 1,
JS: "failure": 0,
JS: "canonical_ids": 0,
JS: "results": [
JS: {
JS: "message_id": "0:1548488437363910%0000000000000000"
JS: }
JS: ]
JS: },
JS: "statusCode": 200,
JS: "headers": {
JS: "null": "HTTP/1.1 200 OK",
JS: "Alt-Svc": "quic=\":443\"; ma=2592000; v=\"44,43,39\"",
JS: "Cache-Control": "private, max-age=0",
JS: "Content-Encoding": "gzip",
JS: "Content-Type": "application/json; charset=UTF-8",
JS: "Date": "Sat, 26 Jan 2019 07:40:37 GMT",
JS: "Expires": "Sat, 26 Jan 2019 07:40:37 GMT",
JS: "Server": "GSE",
JS: "Transfer-Encoding": "chunked",
JS: "X-Android-Received-Millis": "1548488436596",
JS: "X-Android-Response-Source": "NETWORK 200",
JS: "X-Android-Selected-Protocol": "http/1.1",
JS: "X-Android-Sent-Millis": "1548488436437",
JS: "X-Content-Type-Options": "nosniff",
JS: "X-Frame-Options": "SAMEORIGIN",
JS: "X-XSS-Protection": "1; mode=block"
JS: }
JS: }
even it says success. i have not got any notification on android. i'm not using ios.

I am fairly new here, but I realized you are much more likely to get a solution to your problem if you post your Nativescript code here, along with your questions. That way, we can look to see where your code is failing. Regarding this plugin, I will tell you it is imperative you follow every step in the readme file that comes with the plugin. I also had a heck of a time getting this to work, but now I have push notifications working.
Here is an example of NativeScript push notifications in action. This app will also teach you how they achieved their Push Notifications. These are the nicest Push Notifications I have run across yet. NativeScript Push Notification Examples
Please post your page XML and js code-behind, and we'll have a look. Also be sure this value is set properly, as this caused me a headache. Good luck, post your code so we can help!
Tip: Make sure your project number exactly matched your Firebase project value.
var pushSettings = {
senderID: "<ENTER_YOUR_PROJECT_NUMBER>", // Required: setting with the sender/project number
notificationCallbackAndroid: function (stringifiedData, fcmNotification) {
var notificationBody = fcmNotification && fcmNotification.getBody();
_this.updateMessage("Message received!\n" + notificationBody + "\n" + stringifiedData);
}
};

Related

How to update "Going? Yes/No/Maybe" in Google calendar via API?

I am using Google Calendar API to work with events. For example, someone create an event and invites me. So, at the bottom of the event's detail I have 3 options of "Going": YES/NO/MAYBE. My question is how can I answer this by API?
I tried to use an UPDATE request, but it will create a new version of the event in my own calendar instead.
calendar.events.update(
{
calendarId: "primary",
eventId: event.id,
resource: {
start: {
dateTime: event.start.dateTime,
},
end: {
dateTime: event.end.dateTime,
},
attendees: [
{
email: "myemail#gmail.com",
responseStatus: "accepted",
},
],
},
},
(err, response) => {
}
)
For example, how about using patch instead of update as follows?
Modified script:
calendar.events.patch(
{
calendarId: "primary",
eventId: event.id,
resource: {
attendees: [
{
email: "myemail#gmail.com",
responseStatus: "accepted",
},
],
},
},
(err, response) => {
}
)
Reference:
Events: patch

Invalid patch error in Contentful CMA client

I am trying to populating an empty field by using patch method in Contentful. The following piece of code works in one cloned environment but does not work in another.
let patchData: OpPatch[] = [
{
op: 'replace',
path: '/fields/keywords',
value: entryKeyword,
},
];
await cmaClient.entry.patch({ entryId: entryId }, patchData, { 'X-Contentful-Version': entryVersion });
When I try to execute this, receiving a 'Unprocessable Entity' error:
UnprocessableEntity: {
"status": 422,
"statusText": "Unprocessable Entity",
"message": "Could not apply patch to entry: invalid patch",
"details": {},
"request": {
"url": "/spaces/xyz/environments/abc/entries/123456789",
"headers": {
"Accept": "application/json, text/plain, */*",
"Content-Type": "application/json-patch+json",
"X-Contentful-User-Agent": "sdk contentful-management-plain.js/7.54.2;",
"Authorization": "Bearer ...",
"user-agent": "node.js/v14.19.2",
"Accept-Encoding": "gzip",
"X-Contentful-Version": 25,
"Content-Length": 78
},
"method": "patch",
"payloadData": "[{\"op\":\"replace\",\"path\":\"/fields/keywords\",\"value\":\"test keyword\"}]"
},
"requestId": "abcd-123456"
}
I have the same exact access permissions to both environments. What am I missing out on?
I had the same issue - turned out when the entry doesn't have the filed you're trying to patch - it will throw an error like above.

Add user to SharePoint group using Power Automate

I would like to use Power Automate to add a user in as a member to a SharePoint Site using HTTP request.
The flow continues to fail on me and I'm wondering if anyone managed to do this successfully in the past?
I got the Group ID from :
https://{org name}.sharepoint.com/sites/{site name}/_api/web/id
I have attached included the input and output of the HTTP Request (within flow) below
Raw Inputs
{
"host": {
"connectionReferenceName": "shared_sharepointonline",
"operationId": "HttpRequest"
},
"parameters": {
"dataset": "https://{REDACTED}.sharepoint.com/",
"parameters/method": "POST",
"parameters/uri": "_api/web/sitegroups(547ea631-f9d4-411a-a3f5-8af3d5e6225b)/Users",
"parameters/headers": {
"accept": "application/json;odata.metadata=none",
"content-type": "application/json"
},
"parameters/body": "{'LoginName':'i:0#.f|membership|{REDACTED}#{REDACTED}.com'}"
}
}
Raw Outputs
{
"statusCode": 400,
"headers": {
"Pragma": "no-cache",
"x-ms-request-id": "cb6ab59f-909a-2000-ac2f-2217e416179a",
"Strict-Transport-Security": "max-age=31536000; includeSubDomains",
"X-Content-Type-Options": "nosniff",
"X-Frame-Options": "DENY",
"Cache-Control": "no-store, no-cache",
"Set-Cookie": "{REDACTED};Path=/;HttpOnly;Secure;Domain=sharepointonline-we.azconn-we.p.azurewebsites.net,ARRAffinitySameSite={REDACTED}24;Path=/;HttpOnly;SameSite=None;Secure;Domain=sharepointonline-we.azconn-we.p.azurewebsites.net",
"Timing-Allow-Origin": "*",
"x-ms-apihub-cached-response": "true",
"Date": "{TIME & DATE}",
"Content-Length": "457",
"Content-Type": "application/json",
"Expires": "-1"
},
"body": {
"status": 400,
"message": "The expression \"web/sitegroups(547ea631-f9d4-411a-a3f5-8af3d5e6225b)/Users\" is not valid.\r\nclientRequestId: 1cc16a39-7d9c-4290-b07d-4c7329611fb8\r\nserviceRequestId: cb6ab59f-909a-2000-ac2f-2217e416179a",
"source": "https://{REDACTED}.sharepoint.com/_api/web/sitegroups(547ea631-f9d4-411a-a3f5-8af3d5e6225b)/Users",
"errors": [
"-1",
"Microsoft.SharePoint.Client.InvalidClientQueryException"
]
}
}
The error I get is:
"The expression "web/sitegroups(547ea631-f9d4-411a-a3f5-8af3d5e6225b)/Users" is not valid.
clientRequestId: 1cc16a39-7d9c-4290-b07d-4c7329611fb8
serviceRequestId: cb6ab59f-909a-2000-ac2f-2217e416179a"
This makes me think the group ID is incorrect. Can someone please advise if this is incorrect or if I have maybe formatted the uri incorrectly?
Try to use the body like this:
{
'__metadata': {
// Type that you are modifying.
'type': 'SP.User'
},
'LoginName': '<<User Login Name>>'
}

Can't delete account from Firebase

I am creating a simple app using NativeScript where administrators can add and delete users from a a Firebase database. I am being able to add the users easily, but I can't seem to figure out how to delete them. I am following the instructions found in the documentation: https://firebase.google.com/docs/reference/rest/auth#section-delete-account
but when I submit the post request like this:
.post(https://identitytoolkit.googleapis.com/v1/accounts:delete?key=${FIREBASE_API_KEY},{ "idToken": userId }) .... (the rest of the code)
I get the following error:
This is the error I am getting:
JS: ERROR {
JS: "headers": {
JS: "normalizedNames": {},
JS: "lazyUpdate": null
JS: },
JS: "status": 400,
JS: "statusText": "Bad Request",
JS: "url": "https://identitytoolkit.googleapis.com/v1/accounts:delete?key=[MY_API]",
JS: "ok": false,
JS: "name": "HttpErrorResponse",
JS: "message": "Http failure response for https://identitytoolkit.googleapis.com/v1/accounts:delete?key=[MY_API]: 400 Bad Request",
JS: "error": {
JS: "error": {
JS: "code": 400,
JS: "message": "INVALID_ID_TOKEN",
JS: "errors": [
JS: {
JS: "message": "INVALID_ID_TOKEN",
JS: "domain": "global",
JS: "reason": "invalid"
JS: }
JS: ]
JS: }
JS: }
JS: }
I have tried all sorts of things, I have checked questions here, and nothing. Another user mentioned that the user I am trying to delete needs to have signed in before I delete it, but that did not work either. If any of you has any ideas on how to proceed I would appreciate it!
idToken is not the same as the userId, so the first thing you need to do is "log in" (use the SDK) as the user to retrieve his token and then use that token to delete the account.
I was able to do this using the methods described in this doc.

share on linkedin returns "Can not parse JSON share document"

I am trying to share a post on linkedin.
I managed to log in and get returned an id and an accessToken but when I follow the REST APIs way of sharing an update I keep getting:
Error: failed [400] {
"errorCode": 0,
"message": "Can not parse JSON share document.\nRequest body:\n\nError:\nnull",
"requestId": "NWGE7D4LSW",
"status": 400,
"timestamp": 1451699447711
}
My http POST looks like this:
HTTP.post('https://api.linkedin.com/v1/people/~/shares?format=json&oauth2_access_token=' + accessToken, {
'headers': {
'Content-Type': "application/json",
'x-li-format': "json"
},
'comment': "test!",
'visibility': {
'code': "anyone"
}
});
this worked:
HTTP.post('https://api.linkedin.com/v1/people/~/shares?format=json&oauth2_access_token=' + Meteor.user().services.linkedin.accessToken, {
headers: {
"Content-Type": "application/json",
"x-li-format": "json"
},
data: {
comment: "testing",
visibility: {
code: "anyone"
}
}
});

Resources