I have created a watch Channel on my calender and I am successfully receiving all updates from Google PUSH Notifcation.
But I am not able to use that response to get craeted/updated events.
I read few docs and SO questions that I need to use X-Goog-Resource-ID from the response and hit events list API.
But value of this X-Goog-Resource-ID is neither a calender id and neither it is a event id so how can I use this in events list API ?
I am using Python and Service Account for the integration.
Documentaion :
https://googleapis.github.io/google-api-python-client/docs/dyn/calendar_v3.events.html#list
https://developers.google.com/calendar/api/guides/push#making-watch-requests
Response from PUSH :
"X-Goog-Channel-Expiration": "",
"X-Goog-Channel-ID": "",
"X-Goog-Channel-Token": "",
"X-Goog-Message-Number": "",
"X-Goog-Resource-ID": <resource id>,
"X-Goog-Resource-State": "exists",
"X-Goog-Resource-URI": <calender UI>
Google Functions I tried using :
service = build('calendar', 'v3', credentials=credentials)
service.calendars().get(calendarId=X-Goog-Resource-ID).execute()
service.events().list(calendarId=calenderId', eventId=X-Goog-Resource-ID).execute()
Is their any ref Python Example of using digesting Calender PUSH Notification or which API/Function I need to call with what oaarms to get the created/updated events ?
The X-Goog-Resource-ID header holds a value that identifies that particular resource across the APIs. The whole push notifications basically informs you that something has changed on that calendar.
Now if you want to know exactly what changed, I strongly advise you to perform a synchronisation. One way to do this is to perform a full synchronisation and store the nextSyncToken. Then, when you receive a push notification telling you about a change in the calendar, you only have to use the syncToken to know what has changed since your last synchronisation. You can see a working full example on the linked docs.
UPDATE
If you are watching multiple calendars through push notifications, you will need a system in place to track which calendar is being modified at a time. The X-Goog-Resource-ID header maps with the Calendar ID, and it can be used along syncToken to run a events.list() request to receive the updated events.
Related
I want to create a telegram bot to send updates to the groups/channel in which it is added. I used BotFather to create a bot. However, in https://api.telegram.org/bot<BOTAPI>/getUpdates, I'm getting all the messages sent in a channel like this: "channel_post":{"message_id":59,"chat":{"id":-1001192794322,"title":"Nseindia","username":"nseindia_updates","type":"channel"},"date":1588581996,"text":"AMBUJACEM : Bear\nAPOLLOHOSP : Bullish Reversal\nKOTAKBANK : Bullish\nMOTHERSUMI : Bear"}}
This is not a problem now, but as time goes, the json file could get very large and could pose a problem.
Is there any way such that I don't get all the messages in the json present in https://api.telegram.org/bot<BOTAPI>/getUpdates
you should specify the update_id of the latest update you've processed as an offset parameter to getUpdates to make them(updates with less update_id) marked processed and that way they wont come up the next time you call getUpdates.
In telegram's Bot API Docs it says:
By default, updates starting with the earliest unconfirmed update are
returned. An update is considered confirmed as soon as getUpdates is
called with an offset higher than its update_id.
We have a notification which will post data to an application using the application end point.
notification ABC{
post = savedetailsurl
body = {{.|json}}
useBody = true
}
So the end point will save all the details in mysql DB.
Now in our template we call another end point to get the details which we saved using the webhook in notification.
template ABC {
use the " getDetailsUrl" and use the details in forming the email
}
Now the problem is race condition. Sometimes the details are not saved yet in the backend (mysql), and getDetailsUrl is called. So we get the empty result.
Is there are way to solve the race condition.
Bosun's notification system is designed to be very basic. If you want something more advanced you will need to use a separate system to generate the notification details and/or handle the alert workflow. Some people have used pagerduty or other monitoring systems like Shinken to do more advanced notifications or alert management.
Your best bet is to skip the built in notifications and do everything in a external system. You can still use the http://bosun.org/api to integrate with the various alert states (crit/warn/ack/close/etc) or you can change your alerts to use log = true to bypass all the built in states and create your own workflow.
I am tracking user events on the front end with google analytics, but I would also like to send back end events and be able to match up events for the same user in google analytics.
It looks like I should be able to pass the uid parameter: https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#uid but it looks like I also have to pass the tid parameter https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#tid .
The docs say that "All collected data is associated by this ID" (the tid).
What should I pass for the tid? Why can't I just pass the uid, if that is supposed to be a mechanism for tying events together?
I would like the backend to pass the uid to the front end (actually a one-way hash of the email), and then refer to the user in google analytics with this uid.
Is this feasible? I'm a bit confused about how to implement this.
Many thanks!
The "tid" - Tracking ID - is the Web Property, i.e. the "slot" in your Analytics account that the data goes to. If you do not send a tracking id the calls will disappear in limbo. You find the tid in your property settings under "Tracking Code". It is a string that starts "UA-" and so is also sometimes referred to as UA-ID).
The User ID will not help you to identify users, at least not by default, since it is not exposed in the Analytics interface (it should really be called the "cross device identification id", since that is what it's for). You need to create a custom dimension and pass the value of the User ID there if you want to identify users. Per TOS you must take care that no third party, including Google, can resolve your User ID (or any other datapoint) into something that identifies a person, altough of course you can use yourself to connect data to other data in your backend system.
Actually there is a proper way. I've implemented this for myself.
There's a Client ID parameter, that should be passed with your requests.
And here's you have two options:
Create this client id manually (by generating UUID) on server-side and pass it to front-end. Then use this value when you create your tracker and also use it for server-side requests.
//creating of a tracker with manually generated client id
ga('create', 'UA-XXXXX-Y', {
'storage': 'none',
'clientId': '76c24efd-ec42-492a-92df-c62cfd4540a3'
});
Of course, you'll need to implement some logic of storing client id in cookie, for example.
You can use client id that is being generated automatically by ga and then send it to the server-side by your method of choice. I've implemented it through cookies:
// Creates a default tracker.
ga('create', 'UA-XXXXX-Y', auto);
// Gets the client ID of the default tracker and logs it.
ga(function(tracker) {
var clientId = tracker.get('clientId');
//setting the cookie with jQuery help
$.cookie("client-id", clientId , { path : "/" });
});
Then on the back-end just access this cookie and use that client id for your requests.
Also some information con be found here: What is the client ID when sending tracking data to google analytics via the measurement protocol?
I'm looking to have the information submitted on a google form to be on the email notification that I receive. I have tried several things but I can't seem to get it to work. Any ideas?
Create a new form in Google Docs, if you haven’t done that yet, add the necessary fields to the form and save your changes. Now go back to Google Docs and open the spreadsheet corresponding to that particular form.
Choose Tools > Notification rules... and select the option that says Notify me when... A user submits a form. You can also set how frequently you would like to be notified – right away or with daily digest.
Reference: https://support.google.com/docs/answer/91588
To get the notification in your email, you can refer to the this Google add-on.
Also to enable the data or responses to appear in notification you have to enter a script in the form. which basically tries to extract the columns from the spreadsheet. Sample:
var p = SpreadsheetApp.getActiveSheet();
var column = p.getRange(1,1,1,s.getLastColumn()).getValues()[0];
I hope you build the script by yourself!
When I subscribe to all changes of my Drive account, sometimes I receive changes with wrong id. According to my observations changes of specific file are aggregated in last change with some time period.
For example:
If I change file in my drive and if I have received 3 notifications with ids: "#21, #22, #23", I expected that I can get change of "#23", if there is no more changes to that file. But sometimes I receive last change with id greater than it exists. When I use API changes list, I get lastlargestChangeId = receivedChangesId - 1.
I have tested it with google examples and I get the same results:
push notifications test
{"notification_id": "xxxxxxxxxxx", "resource_state": "change", "expiration": "Mon, 07 Jul 2014 13:58:37 GMT", "self_link": "https://www.googleapis.com/drive/v2/changes/3387"}
{
"kind": "drive#changeList",
"etag": "xxxxxxxxxxx",
"selfLink": ".../changes?startChangeId=3340",
"largestChangeId": "3386",
"items": [
...
]
}
Am I wrong?
It seems that Google categorized it as a bug:
https://code.google.com/a/google.com/p/apps-api-issues/issues/detail?id=3706
Star it so Google can prioritize it.
Here is the official answer:
After talking with our engineers, this actually is working as
intended. The change ID given in the push notification (the ID and the
self link that contains that same ID) remain valid only as long as
there are no newer changes on a particular resource. Take the
following example scenario on a user's drive with push notifications
being sent for all changes. 1) Resource A (a file or folder, etc)
changes. 2) Drive API sends a push notification with a change ID
(example 1234). 3) This change ID (and the selflink) can be used now
to successfully pull up the change. 4) Resource A changes again. 5)
Drive API sends a push notification with change ID 1235. Note that
change IDs are monotonically increasing. 6) Accessing the earlier
change ID (1234) through a changes.get or the self link will 404 now
because there is a newer change on the same resource. 7) You can still
access change ID 1235 here.
In general, you should not expect to be able to get a particular
change ID with changes.get. Any resource is only in the changes stream
once. So as soon as the resource has a newer change, the old change ID
is invalid. Some commenters have noted that you can do changeID - 1 to
get this change. However, this will not always work. In my testing, I
have gotten a 404 on both the change ID and for change ID - 1.
Instead, you should sync a given set of resources and note the largest
change ID of that set. Then, when you get push notifications in the
future, see if the change ID you get in the push notification is newer
than the largest you stored. If so, use changes.list in order to get
all of the resource changes between the last change ID you have seen /
stored and the one you just received.
tldr; Do not count on change IDs existing with changes.get. Use
changes.list instead to get all changes from a base change ID to the
change ID you get in the push notification.
https://code.google.com/a/google.com/p/apps-api-issues/issues/detail?id=3706