I want to start of by saying that I know there are a couple of questions touching on exactly this, but none of them is exactly my problem. Also, I want to add that I have been pulling my hair on this for some time now.
My problem is that I am trying to create an automated Google channel refresh, specifically a watch-channel on events. I already have a fully working setup where we can sync both ways to Google calendar. The only problem that is left to crack is that I currently create and refresh the watch-channels via Postman, which is not optimal to say the least.
I have set up a service account that is working as expected when fetching, synchronising, creating and deleting events in multiple calendars. I have a domain that I successfully proven ownership of and the site uses SSL from a trusted source. As I said, everything else is working as expected.
To the problem at hand; When trying to create a new watch-channel in a command I get the error message in the subject of this question:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "push.webhookUrlUnauthorized",
"message": "Unauthorized WebHook callback channel: https://subdomain.yourdomain.app"
}
],
"code": 401,
"message": "Unauthorized WebHook callback channel: https://subdomain.yourdomain.app"
}
}
(The URL's are of course examples, as I do not want to share the correct information at this point.)
I have followed the examples seen in other questions about the exact problem, but they do nothing for me, and they all seem to be kicks in the dark as the documentation says very little about this. The code that is creating the channel looks as follows:
$calendar = GoogleCalendarFactory::createForCalendarId($calendarId);
$service = $calendar->getService();
$channel = new Google_Service_Calendar_Channel();
$channel->setId('a-random-id');
$channel->setType('web_hook');
$channel->setAddress('https://subdomain.yourdomain.app');
$result = $service->events->watch($calendarId, $channel);
I do have verified ownership of both "subdomain.yourdomain.app" and "yourdomain.app", and I do have both of them as added domains in my domain verification. I have tried entering them both with HTTPS, HTTP and without any schema, to no avail.
Please, help me solve this once and for all.
I got this working, and here is how:
For anyone who comes here in the future with the same problem, my tip is creating a new google account for the project. I know this might not be possible for many of you, but it worked for me, and I can only speculate on why.
To reiterate, my solution was as follows:
If I am to guess wildly, I think something with the OAuth playground got messed up in an early stage of our testing. Why this did not mess upp the other functions in the Google Calendar API I have no answer for, but it's the only point where I can imagine this to start acting as it did.
I hope that this might help at least one of you. And if I come back here in 5 years time looking for the answer, at least I will have helped myself.