Hmm, so a 401 usually means bad credentials, and would be an error coming from Google.
Google is really often aggressive about rate limiting, that thread mentions:
the documentation from google says only 1x access per 10 min ?
is it really that strict now ? anyone have any experience with this ?
Maybe just try waiting ~15 minutes or so between requests? The current webhook system will retry requests if they get an error, so it’s possible that’s aggravating the rate limits more.
I checked on our end and I don’t see any unusual rate limiting of requests to Google as far as I know, and those wouldn’t manifest as http error status codes from us. I’m happy to reach out to Google as well if waiting a little longer doesn’t fix it.
So. I was able to find a very easy alternative method to gmail atom feed. I found this tutorial on google script and decided to use it…
Basically, it provides you with a URL that will return the data in the format you request, so I simply altered it to return a JSON:
/* Gmail Counter by Amit Agarwal */
/* Published on 06/17/2013 */
function doGet() {
var cache = CacheService.getPublicCache();
var counter = cache.get("gmail-counter");
// Cache the counter to stay within the Apps Script quota
if (!counter) {
counter = GmailApp.getInboxUnreadCount();
// Cache the counter value for 20 minutes
cache.put("gmail-counter", counter, 1200);
}
// You can customize the output message
counter = "{\"unread\":" + counter + "}" //<<<<<< this bit
// Output the result in plain text format
return ContentService.createTextOutput(counter)
.setMimeType(ContentService.MimeType.TEXT);
}
then created a new webhook with the URL that Google provided:
Thats nice. but unfortunately I don’t get the webhook running as you showed here. After configuring the google script it tells me the correct number of unread emails if I use the generated URL.
But after creating the webhook, all I see is an empty data field
Ok after reading the instruction again carefully its working now fine (especially after setting the script rights to “Anyone, even anonymous” instead of just “Anyone”).