Need help registering Google Cloud Function URL as verified domain to receive push notifications - google-calendar-api

Am trying to call google calendar's push notification apis. I have written a google cloud function which just returns a response containing request body and headers. I want to use this google cloud function url as the receiving url for the push notification. The google docs mention steps to verify and register the domains, as part of which it asks me to upload a binary. Not sure how do upload a binary against this cloud function domain. My domain looks like https://asia-northeast1-project-name.cloudfunctions.net
This was my request for registering push notification:
Request:
POST
https://www.googleapis.com/calendar/v3/calendars/primary/events/watch?key={YOUR_API_KEY}
{ "id": "404713b9-d880-437d-b890-83715f01af7c", "type": "web_hook",
"address":
"https://asia-northeast1-huddle-quick-solutions.cloudfunctions.net/suratCalendarNotifications" }
Response:
{ "error": { "errors": [ {
"domain": "global",
"reason": "push.webhookUrlUnauthorized",
"message": "Unauthorized WebHook callback channel: https://asia-northeast1-project-name.cloudfunctions.net/path" } ], "code": 401, "message": "Unauthorized WebHook callback
channel:
https://asia-northeast1-project-name.net/path"
} }

Related

Google Calendar API Freebusy query returns "notFound" error

I'm trying to learn how to use this query; I created an API key and used Postman to
Post https://www.googleapis.com/calendar/v3/freeBusy?key="THE_API_KEY"
with this request body:
{
"timeMin": "2022-11-16T00:00:31-00:00",
"timeMax": "2022-11-16T14:00:00-00:00",
"groupExpansionMax": 100,
"calendarExpansionMax": 50,
"items": [
{
"id": "MY_OWN_GMAIL_ADDRESS"
},
{
"id": "OTHER_GMAIL_ADDRESS"
}
]
}
and got this response:
{
"kind": "calendar#freeBusy",
"timeMin": "2022-11-16T00:00:31.000Z",
"timeMax": "2022-11-16T14:00:00.000Z",
"calendars": {
"MY_OWN_GMAIL_ADDRESS": {
"errors": [
{
"domain": "global",
"reason": "notFound"
}
],
"busy": []
},
"OTHER_GMAIL_ADDRESS": {
"errors": [
{
"domain": "global",
"reason": "notFound"
}
],
"busy": []
}
}
}
What am I missing?
The Freebusy: query returns information about weither or not there is an event at the time of the request.
This method does not require authorization when being used against a public google calendar. There are a number of such calendars the holiday calendars are all public. You could also set your own calendar to public if you wish and then you would be able to use use an api key to access it.
API keys give you access to public methods only.
In order to access private user data. You need to be authorized using oauth2 with one of the following scopes.
If you do not have access to a calendar then it will return not found as you cant see it so your not going to be able to find it.
The solution i your case to fix your issue would be to either set the calendar to public and continue to use the api key. You will only be able to preform read actions against the calendar.
Or to switch to using oauth2 and send an authorization header with a bearer token.
Your post didnt include the Authorization header. Did you include it in your Postman Request?
Your need to send your Access Token as a Bearer Token in the Authorization Header
You can see an example for a request here:
https://developers.google.com/calendar/api/v3/reference/freebusy/query?apix=true#try-it

Flutter send firebase notification to token

So i have a chat app and i want it so that i can get a notification once someone sends me a message. The thing is that i implemented firebase messaging and i can receive a notification if i send it from firebase. I want to add it such as once i press the send button i can directly send the notification to a token within the app for instance something like:
send notification{
to token : here the receiver token
title : the title of the notification
description : the description of the notification
}
is it possible to have something like this?
Just for helping,
If anyone wants to use REST POST API, here it is, use the Postman with below configuration
URL:
https://fcm.googleapis.com/fcm/send
Header:
"Content-Type": "application/json",
"Authorization": "key=<Server_key>"
BODY:
{
"to": "<Device FCM token>",
"notification": {
"title": "Check this Mobile (title)",
"body": "Rich Notification testing (body)",
"mutable_content": true,
"sound": "Tri-tone"
},
"data": {
"url": "<url of media image>",
"dl": "<deeplink action on tap of notification>"
}
}

When using fcm http v1, data messages do not arrive normally after about 20 times

I wrote google translator. Please understand this part.
hi.
There was a problem when upgrading the API version from FCM HTTP to FCM HTTP v1.
FCM HTTP v1 API request was made through POSTMAN.
Below is the sending message body.
{
"message": {
"topic": "this_is_test_topic",
"data": {
"body": "1234567890"
},
"android": {
"priority": "high"
}
}
}
When I made the above request, IOS client received it normally even though it was sent once or twice per second.
However, the ANDROID client did not receive a message from FCM for a certain period of time after receiving the first 20 times.
The message could be transmitted once more after a certain time.
This was the same as the limitations of compact messages in the FCM documentation.
Link: https://firebase.google.com/docs/cloud-messaging/concept-options?hl=en#collapsible_throttling
However, I didn't put any data related to the miniature in the message I sent.
If you make a request to the existing FCM HTTP with the same topic, data is received normally. Below is the corresponding code.
{
"to": "this_is_test_topic",
"data": {
"body": "1234567890"
}
}
If the FCM HTTP v1 API is requested using the same topic and token instead of topic, data is received normally. Below is the corresponding code.
{
"message": {
"token": "asdkjasldjalksdjlk*******************",
"data": {
"body": "1234567890"
},
"android": {
"priority": "high"
}
}
}
all request response status code is 200

First request to a webhook

To create a webhook, it has to pass the following validation:
Receive a GET request onto the webhook URL and read a specific "challenge" field from the query.
Send this field back to where the request comes.
Can this be implemented in an Integromat app?
Yes, you can use the verification directive for this purpose.
The code would look something like this:
{
"verification": {
"condition": "{{if(query.challenge, true, false)}}",
"respond": {
"status": 200,
"type": "json",
"body": {
"challenge": "{{query.challenge}}"
}
}
},
"response": {
"output": "{{body}}"
}
}
It's up to you to specify the verification condition so that the platform will be able to tell if the incoming message is a verification request or a regular webhook payload.

The request was missing an Authentication Key with push notification in firebase

I'm trying to send a push notification via REST API Firebase by Postman for specific user I followed below request pattern:
POST request with below URL :
https://fcm.googleapis.com/fcm/send?key=**my Web API key**
and the Body is
{ "data":
{
"title": "Firebase notification",
"detail": "I am firebase notification. you can customise me. enjoy"
},
"to" : "USER UID"
}
but the problem is it returns The request was missing an Authentication Key.
Kindly follow the steps as per bellow :
API URL: https://fcm.googleapis.com/fcm/send/
Request Method Post
Add 2 Key-value pairs in Header section like this
Content-Type : application/json
Authorization: key=[Your server key] (Make sure that no space allowed)
For body choose raw data (JSON)
{ "data": { "title": "Firebase notification", "detail": "I am firebase notification. you can customise me. enjoy" }, "to" : "USER UID" }

Resources