1

I have a property website where I have listed multiple properties. Each property has a Google Calendar and when the property is booked on that particular day, then a note is added on that day for that particular calendar.

I was doing all this manually, where I was updating the HTML of the website by showing the availability with a layout like this.

enter image description here

Now I am trying to make all this automated by using the Google Calendar API where I can display the booking of each property in a calendar like the example above.

I am trying to use the Google API PHP Client Library which is located at https://github.com/google/google-api-php-client

My biggest problem here is that I am unable to find any basic example of this also over the internet. Google pages are not showing the full examples.

For example, the guide page of Google shows just one example of "books", which I don't need at all.

I have searched all over the internet for some basic examples of the code but unable to find it at all. I search stackoverflow itself but all the codes that I have find are really confusing and all of them are different.

Moreover, most of them already "know" about it so there is no way to understand what is required.

If someone has a simple example where I can pull events of a day of a calendar, please post it here.

Also if you know of some other way to display the availability like the image above, would be great help !

Thanks.

Patrick S
  • 87
  • 5
  • 11
  • Follow the documentation here https://developers.google.com/google-apps/calendar/quickstart/php and if you have any errors, let us know. – Morfinismo Mar 08 '17 at 20:41
  • Answer the question after reading it dude.... – Patrick S Mar 08 '17 at 21:30
  • I did. I'm just trying to help you. Don't expect us to do everything for you if you haven't at least tried something yet and post the code you are using. Maybe this post can give you an idea http://stackoverflow.com/questions/42177931/google-calendar-api-get-events-on-current-week. Good luck! – Morfinismo Mar 08 '17 at 21:38
  • The link you gave doesn't use the Google API PHP client. And neither did I expect for anyone to do anything for me. I just asked for a sample code using Google API PHP Client, the link for the I gave above. Plus I already mentioned that I have search all over the internet and stackoverflow but cannot find a "good" source. – Patrick S Mar 08 '17 at 22:38
  • Also there is no need to -1 on the question just because I asked you to read the question before answering. I am not looking for a google search answer. I am looking for an answer from someone who has ACTUALLY done this thing. Just searching on stackoverflow and posting link here is not the answer. – Patrick S Mar 08 '17 at 22:40
  • It is using the PHP client library. You are not able to tell perhaps because you lack experience. Nevertheless, maybe you can find what you need here http://www.daimto.com/accessing-google-calendar-with-php-oauth2/ – Morfinismo Mar 08 '17 at 22:56

1 Answers1

2

What the heck, I'll repost an answer I gave from this question:

if($refresh_token_accessed_from_my_database) {
            //If session contains no valid Access token, get a new one
            if ($client->isAccessTokenExpired()) {
                $client->refreshToken($refresh_token_accessed_from_my_database);
            }
            //We have access token now, launch the service
            $this->service = new Google_Service_Calendar($client);
        }
        else {
            //User has never been authorized, so let's ask for the ok
            if (isset($_GET['code'])) {
                //Creates refresh and access tokens
                $credentials = $client->authenticate($_GET['code']);

                //Store refresh token for further use
                //I store mine in the DB, I've seen others store it in a file in a secure place on the server
                $refresh_token = $credentials['refresh_token'];
                //refresh_token->persist_somewhere()

                //Store the access token in the session so we can get it after
                //the callback redirect
                $_SESSION['access_token'] = $client->getAccessToken();
                $redirect_uri = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
                header('Location: ' . filter_var($redirect_uri, FILTER_SANITIZE_URL));
            }

            if (!isset($_SESSION['access_token'])) {
                $auth_url = $client->createAuthUrl();
                header('Location: ' . filter_var($auth_url, FILTER_SANITIZE_URL));
            }

            if (isset($_SESSION['access_token']) && $_SESSION['access_token']) {
                $client->setAccessToken($_SESSION['access_token']);
                $this->service = new Google_Service_Calendar($client);
            }

When I built my project I started from the tutorial Morfinismo post in the comments, but I had a couple of problems following that one. I've made comments to describe the general flow and some potential problem points, you may want to compare those notes with the other tutorial if you're not too clear about what is going on.

Community
  • 1
  • 1
Pacio
  • 523
  • 4
  • 11