Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Google Calendar API v3 'events/watch' Returns Null "Address" in Response Despite No Errors #2620

Open
Romasa102 opened this issue Aug 25, 2024 · 1 comment

Comments

@Romasa102
Copy link

Romasa102 commented Aug 25, 2024

Environment details

  • OS: Linux 64bit
  • PHP version: 7.4.33
  • Package name and version: google-api-php-client

Problem

I'm attempting to receive notifications from Google Calendar using the google_calendar_api_v3/events/watch API (https://developers.google.com/calendar/api/v3/reference/events/watch). Although no errors are returned, the response includes a null "address," and the API ultimately fails to work as expected. I can successfully fetch the calendar and events list with the current authorization setup. The PHP script is part of a backend API for an application, and it will not be accessed directly by users via a browser.

I have already verified that the SSL/TLS certificate is correct, and I changed the redirect URL from one with an underscore to one with a hyphen to avoid potential issues.

Here is the relevant code:

index.php

require_once '../google-api-php-client/vendor/autoload.php';
$this->client = new Google\Client();
$this->client->setScopes(Google_Service_Calendar::CALENDAR);
$this->client->setAuthConfig('../client_secret.json');
$this->client->setAccessType('offline');
$refresh_token = "__REFRESHTOKEN__";
$this->client->fetchAccessTokenWithRefreshToken($refresh_token);
$access_token = $this->client->getAccessToken();
$this->client->setAccessToken($access_token);
$this->service = new Google_Service_Calendar($this->client);
$channel = new Google_Service_Calendar_Channel($this->client);
$channel->setId("1412");
$channel->setType("web_hook");
$channel->setAddress("https://sub-domain.example.com/calendar/push_notifications");
$calendarId = "primary";
$watchResponse = $this->service->events->watch($calendarId, $channel);

ClientSecret.json

{
    "web": {
        "client_id": "__CLIENT_ID__",
        "project_id": "__PROJECT_ID__",
        "auth_uri": "https://accounts.google.com/o/oauth2/auth",
        "token_uri": "https://oauth2.googleapis.com/token",
        "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
        "client_secret": "__CLIENT_SECRET__",
        "redirect_uris": [
            "https://{__PROJECT_ID__}.firebaseapp.com/__/auth/handler",
            "https://sub-domain.example.com/",
            "https://sub-domain.example.com/calendar/push-notifications"
        ],
        "javascript_origins": [
            "http://localhost",
            "http://localhost:5000",
            "https://{__PROJECT_ID__}.firebaseapp.com"
        ]
    }
}

Response.json

{
    "address": null,
    "expiration": "__EXPIRATION__",
    "id": "1412",
    "kind": "api#channel",
    "params": null,
    "payload": null,
    "resourceId": "__RESOUCE_ID__",
    "resourceUri": "https:\/\/www.googleapis.com\/calendar\/v3\/calendars\/primary\/events?alt=json",
    "token": null,
    "type": null
}

What I've tried

Since the initial redirectURL included '_' we changed it to '-'.
Confirmed that the SSL/TLS-certificate is correct.

Thanks!

@risingphoenix
Copy link

I am also having this problem.
The call is made by a script in a local environment, maybe that's why a url is not accepted?
However, in my case, even in production the request for a new Watch Channel will be made by a script, so if there was a control on a source domain it would not work... but it seems a bit strange as a possible reason for the non-acceptance of the parameter.

Have you found an alternative way to solve it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants