Google calendar api Push notification: 401 - Unauthorized WebHook callback channel

后端 未结 3 433
暗喜
暗喜 2021-01-07 01:18

Any solution for the issue. This seems to be not working

{
 \"error\": {
  \"errors\": [
   {
    \"domain\": \"global\",
    \"reason\": \"push.webhookUrlUn         


        
相关标签:
3条回答
  • 2021-01-07 01:20

    Push notifications require that you've verified domain ownership, so cannot be created in the API Explorer, as it doesn't provide a means of associating the requests with a project on which you've verified ownership. This can be done in the OAuth Playground, if you use project credentials, as detailed below:

    • Configure the API project:

      1. Access your API project at https://console.developers.google.com/project/.
      2. Ensure that you've registered the HTTPS version of your site according to the instructions at https://developers.google.com/admin-sdk/directory/v1/guides/push#registering-your-domain.
      3. From the Products & services menu (three horizontal lines at the top left), select ‘API Manager’, then the ‘Enabled APIs’ tab, and ensure that the appropriate API is enabled.
      4. Select ‘Credentials’, and from the ‘Add credentials’ drop down list, select ‘Oauth client ID’.
      5. If not previously configured, you’ll be prompted to configure the consent screen, so click ‘Configure consent screen.’ If so, enter your email address, a product name, and click ‘Save.’
      6. Select 'Web Application', and enter a Name for the client id.
      7. Under 'Authorized Javascript Origins' enter 'https://developers.google.com.'
      8. Under 'Authorised redirect URIs', enter 'https://developers.google.com/oauthplayground'.
      9. Click ‘Create Client ID’.
    • Configure the OAuth Playground:

      1. Navigate to https://developers.google.com/oauthplayground/.
      2. Click ‘OAuth 2.0 Configuration’ (gear icon) in the top right hand corner.
      3. Check ‘Use your own OAuth credentials’.
      4. Paste the ‘Client ID’ from the ‘Credentials’ page of your API project in to ‘OAuth Client ID’.
      5. Paste the ‘Client Secret’ from the ‘Credentials’ page of your API project in to ‘OAuth Client secret’.
      6. Click ‘Close.’
    • Authorize API requests:

      1. Enter https://www.googleapis.com/auth/admin.directory.user in ‘Input your own scopes’.
      2. Click ‘Authorize APIs’.
      3. You’ll be prompted to permit API access to your domain, so click ‘Allow access’.
      4. You’ll see the response ‘HTTP/1.1 302 Found.’ Click ‘Exchange authorization code for tokens’.
      5. You should see ‘HTTP/1.1 200 OK’. The page will drop down to the next section in a few moments.
      6. Select POST as the 'HTTP method.'
      7. Click 'Enter request body', and enter your request, for example:

        { "id": "c887ce64-adc8-4007-952c-a172c376b30d", "type": "web_hook", "address": "https://example.com/watch" }

      8. Click 'Close' when done.

      9. Enter the URI for the resource you want to monitor, replacing {calendarId} with the appropriate calendar ID, for example: https://www.googleapis.com/calendar/v3/calendars/user@example.com/events/watch
      10. Click 'Send the request.'

      11. You should receive a response similar to:

        { "resourceId": "DmuNd7MI-w7qwW1FxDNf_pdqk7Y", "kind": "api#channel", "expiration": "1507327087000", "id": "c887ce64-adc8-4007-952c-a172c376b30d", "resourceUri": "https://www.googleapis.com/calendar/v3/calendars/user@example.com/events?maxResults=250&alt=json" }

    Note: Push notifications for other APIs, for example the Directory API, may have additional parameters. Check the relevant Reference documentation for details.

    0 讨论(0)
  • 2021-01-07 01:21

    To use Push Notifications in Google Calendar make sure you followed the instructions here:

    1. Register the domain of your receiving URL in Google Dev Console. Go to Credentials and click Domain Verification for the webhook setup.

    For example, if you plan to use https://yourdomainexample.com/notifications as your receiving URL, you need to register https://yourdomainexample.com. Set up your receiving URL, or "Webhook" callback receiver.

    1. This is an HTTPS server that handles the API notification messages that are triggered when a resource changes.

    2. Set up a notification channel for each resource endpoint you want to watch.

    A channel specifies routing information for notification messages. As part of the channel setup, you identify the specific URL where you want to receive notifications. Whenever a channel's resource changes, the Google Calendar API sends a notification message as a POST request to that URL.

    You may also check this SO thread for additional reference.

    0 讨论(0)
  • 2021-01-07 01:33

    This fix helped me to solve the issue. I had not mentioned the callback link in the google applications authorized redirect urls. Upon addition i was able to generate watch events and was able to receive push notification message as well

    0 讨论(0)
提交回复
热议问题