in

Separate Server for Google API – JavaScript – SitePoint Forums

1674864537 cf11b3ed553d6c359d3dcc08377cc4b121fe8bf0

[ad_1]

This page describes how to set up and use the Google Calendar API. Talk about a Python server. I would like to know, is it required?Or can I use another web server like XAMPP or a live server? Thanks


The answer to my question is no. it is not required. I used Docker running XAMMP to connect and use the sample to get all calendar events.

Hi @philhagen, you might not actually need docker or even a full XAMPP setup…as I understand they use Python just to serve a simple static file server I’m using index.html page. So you can also use the built-in PHP dev server like this:

php -S localhost:8000

…and open http://localhost:8000 in your browser. Or use any other development server like this vscode plugin. This is what I use all the time for such things.



1 like

Thank you for your reply. i watched it However, I was trying to stay consistent with other things my application is doing. I wanted to use my current server to run another, simple or not.Thank you



1 like

If anyone has an idea on how to change the code of the linked page to be able to pull all events It’s not just about upcoming events. please let me know.Thank you

I do not know well, listUpcomingEvents()they are setting

request = {
  'calendarId': 'primary',
  'timeMin': (new Date()).toISOString(),
  // ...
}

So you probably only need to set timeMin Until some date in the past (or you can omit it entirely).

edit: yes timeMin The parameter is actually optional, so leave it unchecked to see the full list of events.

thank you! Very helpful. Funny enough, I tried to eliminate it. I didn’t realize that these requests can also be affected by caching. I couldn’t see anything until I closed the window and opened a new one. When you said it was working, I noticed something strange was going on.



1 like

Also… is this what they say should work for injecting events?

<!DOCTYPE html>
<html>
  <head>
    <title>Google Calendar API Quickstart</title>
    <meta charset="utf-8" />
  </head>
  <body>
    <p>Google Calendar API Quickstart</p>

    <!--Add buttons to initiate auth sequence and sign out-->
    <button id="authorize_button" onclick="handleAuthClick()">Authorize</button>
    <button id="signout_button" onclick="handleSignoutClick()">Sign Out</button>

    <pre id="content" style="white-space: pre-wrap;"></pre>

    <script type="text/javascript">
      /* exported gapiLoaded */
      /* exported gisLoaded */
      /* exported handleAuthClick */
      /* exported handleSignoutClick */

      // TODO(developer): Set to client ID and API key from the Developer Console
      const CLIENT_ID = '<YOUR_CLIENT_ID>';
      const API_KEY = '<YOUR_API_KEY>';

      // Discovery doc URL for APIs used by the quickstart
      const DISCOVERY_DOC = 'https://www.googleapis.com/discovery/v1/apis/calendar/v3/rest';

      // Authorization scopes required by the API; multiple scopes can be
      // included, separated by spaces.
      const SCOPES = 'https://www.googleapis.com/auth/calendar';

      let tokenClient;
      let gapiInited = false;
      let gisInited = false;

      document.getElementById('authorize_button').style.visibility = 'hidden';
      document.getElementById('signout_button').style.visibility = 'hidden';

      /**
       * Callback after api.js is loaded.
       */
      function gapiLoaded() {
        gapi.load('client', initializeGapiClient);
      }

      /**
       * Callback after the API client is loaded. Loads the
       * discovery doc to initialize the API.
       */
      async function initializeGapiClient() {
        await gapi.client.init({
          apiKey: API_KEY,
          discoveryDocs: [DISCOVERY_DOC],
        });
        gapiInited = true;
        maybeEnableButtons();
      }

      /**
       * Callback after Google Identity Services are loaded.
       */
      function gisLoaded() {
        tokenClient = google.accounts.oauth2.initTokenClient({
          client_id: CLIENT_ID,
          scope: SCOPES,
          callback: '', // defined later
        });
        gisInited = true;
        maybeEnableButtons();
      }

      /**
       * Enables user interaction after all libraries are loaded.
       */
      function maybeEnableButtons() {
        if (gapiInited && gisInited) {
          document.getElementById('authorize_button').style.visibility = 'visible';
        }
      }

      /**
       *  Sign in the user upon button click.
       */
      function handleAuthClick() {
        tokenClient.callback = async (resp) => {
          if (resp.error !== undefined) {
            throw (resp);
          }
          document.getElementById('signout_button').style.visibility = 'visible';
          document.getElementById('authorize_button').innerText="Refresh";
          await listUpcomingEvents();
        };

        if (gapi.client.getToken() === null) {
          // Prompt the user to select a Google Account and ask for consent to share their data
          // when establishing a new session.
          tokenClient.requestAccessToken({prompt: 'consent'});
        } else {
          // Skip display of account chooser and consent dialog for an existing session.
          tokenClient.requestAccessToken({prompt: ''});
        }
      }

      /**
       *  Sign out the user upon button click.
       */
	   
	   var event = {
		  'summary': 'Google I/O 2015',
		  'location': '800 Howard St., San Francisco, CA 94103',
		  'description': 'A chance to hear more about Google\'s developer products.',
		  'start': {
			'dateTime': '2023-05-28T09:00:00-07:00',
			'timeZone': 'America/Los_Angeles'
		  },
		  'end': {
			'dateTime': '2023-05-28T17:00:00-07:00',
			'timeZone': 'America/Los_Angeles'
		  },
		  'recurrence': [
			'RRULE:FREQ=DAILY;COUNT=2'
		  ],
		  'attendees': [
			{'email': 'lpage@example.com'},
			{'email': 'sbrin@example.com'}
		  ],
		  'reminders': {
			'useDefault': false,
			'overrides': [
			  {'method': 'email', 'minutes': 24 * 60},
			  {'method': 'popup', 'minutes': 10}
			]
		  }
	   };

	   var request = gapi.client.calendar.events.insert({
		  'calendarId': 'primary',
		  'resource': event
	   });

	   request.execute(function(event) {
		  appendPre('Event created: ' + event.htmlLink);
	   });

    </script>
    <script async defer src="https://apis.google.com/js/api.js" onload="gapiLoaded()"></script>
    <script async defer src="https://accounts.google.com/gsi/client" onload="gisLoaded()"></script>
  </body>
</html>

[ad_2]

Source link

What do you think?

Leave a Reply

GIPHY App Key not set. Please check settings

    128363487 wathan bbc

    Ex-women's rugby boss says colleague made rape comment

    128380041 martinkeown

    Arsenal 3-2 Man Utd: ‘Echoes of Wenger’s title-winners’ – Martin Keown analysis