Friday 25 October 2019

Google Calendar API Tutorial | Connect Calendar With PHP | Display And A...



Download VENDOR Folder (Only for PHP version 7.2+): https://unpossiblepog.com/research-and-development/php/Vendor-Folder-For-Google-Sheet-Drive-Calendar-With-PHP-Version-7.2-And-Onward
Watch above video for complete guidance

Please avoid or flag spams/hateful comments. And do not spam. Enjoy :)
Enable GOOGLE CALENDAR:-
https://calendar.google.com/calendar/
Install LUBUNTU, XAMPP & SUBLIME TEXT:-
https://youtu.be/X09awd5Q8Bk
Install Composer (In windows):-
https://www.youtube.com/watch?v=BGyuKpfMB9E
Install Composer (In LINUX):-
sudo apt install composer
Connect Calendar With PHP:-
https://developers.google.com/calendar/quickstart/php
Insert Event:-
https://developers.google.com/calendar/v3/reference/events/insert
------------------------------------------------
Social Media Links :-
Subscribe my Channel:-
http://www.youtube.com/user/SanketRooney?sub_confirmation=1
Facebook Page:-
https://www.facebook.com/UnpossibleNS
Twitter Account:-
https://twitter.com/UnpossiblePOG
Blog :-
https://unpossiblepog.blogspot.in/
------------------------------------------------
Hey guys, this is UNPOSSIBLE POG.
In this video, I shall connect “PHP” with “Google Calendar” using “Google calendar API”.
Before we start, If you have linux, then its great, otherwise install linux in “Oracle Virtualbox”.I would prefer a debian family like Ubuntu, Lubuntu, Linux Mint, Xubuntu.
The link of “How to install composer” is in the description.
Of course you can use windows, but  when I was trying to connecting, it was vary frustrating because not only PHP wasn’t connecting but the xampp was getting corrupted when I tried to install composer.
In this video, I am using LUBUNTU, which is lightweight operating system.
For complete setup guidelines for Lubuntu and xampp, click on the right top corner.
And you must have “Google Account”
And also, google did provide some guidelines, but some of them are not properly explained or some code are not ready to go.
Let’s get started.
Open up the browser, and search for “Google Calendar quickstart php”.
Go to the link or link is in the description.
So as they say, we need, php version more than 5.4.
Now we need to install composer.
As you can see, I already installed it.
Then we need to enable “Google calendar ”. Click on the button, it will automatically enable it for us.
It may take more than one minute.
Now, open notepad, and store those values just for backup.
Although, what we actually need is “credentials.json” file, so download it.
Now go to downloaded location, create a new folder in htdocs folder inside xampp, give it any name. Then paste “credentials.json” file in it.
Now, open that folder in terminal, and paste the command that they provided. Hit ENTER.
It may take several minutes because it is downloading lot of files from google server. Have patients.
Now we are good to go.
Next is to copy the code, create a file inside “API” folder, create a new file with any random name. Paste that sample code. the close php tag.
Here, they made some code which is not ready to go. So copy that DIR line, and paste it before “credentials.json” somewhere at line 17.
Now in terminal, make sure that, we are at same location where “quickstart.php” is.
Run the file by typing command “php quickstart.php”.
Oops, I forgot to give forward slash. My bad.
Rerun it, now it asks for varification code. So copy the link above that line.
Paste it in “Browser’s URL.” Hit enter.
Sign in, it is preventing you, just click on “Advanced” then click on “ Go To quickstart(unsafe)”.
Now notice that line says “View Your Calendar”. It means we only have an access to view calendar. Allow it.
Now, they provide you the verification code, copy it, paste it for backup and paste it in “terminal”.
Now the output says, “No Upcoming event found” because we didn’t create any events yet.
So go to google, search for “google calendar”, click on this link.
You will see your calendar.
Now you notice that red line which is the current time, I shall make two events. 1 before the red line and 1 after the red line.
Now, lets rerun it.
You will see, that that it is showing the upcoming event but not past event.
Before that, we shall make run it on browser.
When, we run it on browser, it doesn’t allow you to.
It shows the error :-
“Fatal error :  Uncought Exception: This application must be run on command line”
So just comment those lines. and refresh the page.
And boom, your code is now connected with browser.
If you want all events. Then we shall first check the output of date(c).
We shall copy that and change date to 0000-01-01.
Now we are getting all results.
If you observe, thare are several attributes of each event like description, timezone etc.
So for that, there are functions available. We shall receive the description of each event by call getDescription() function.
Now lets add some events, shall we?
Open browser, search for “insert calendar event API”. Search for “PHP”.
Copy this code, and paste it within our code.
You can paste it at the end of code if you want to. But you must paste it somewhere below “events” variable.
Now, they instructed us to change the scope to CALENDAR.
So Copy-paste it above.
Now, the next instruction is incorrect. We don’t have to delete “credentials.json” file.
Open, “token.json” and remove ”.readonly“ from scope variable.
Now it is giving me the error called “insuffucientPermission”. Which is obvious.
Error goes like this:-
...............{
Fatal error: Uncaught Google_Service_Exception: { "error": { "errors": [ { "domain": "global", "reason": "insufficientPermissions", "message": "Insufficient Permission: Request had insufficient authentication scopes." } ], "code": 403, "message": "Insufficient Permission: Request had insufficient authentication scopes." } } in /opt/lampp/htdocs/api/vendor/google/apiclient/src/Google/Http/REST.php:118 Stack trace: #0 /opt/lampp/htdocs/api/vendor/google/apiclient/src/Google/Http/REST.php(94): Google_Http_REST::decodeHttpResponse(Object(GuzzleHttp\Psr7\Response), Object(GuzzleHttp\Psr7\Request), 'Google_Service_...') #1 /opt/lampp/htdocs/api/vendor/google/apiclient/src/Google/Task/Runner.php(176): Google_Http_REST::doExecute(Object(GuzzleHttp\Client), Object(GuzzleHttp\Psr7\Request), 'Google_Service_...') #2 /opt/lampp/htdocs/api/vendor/google/apiclient/src/Google/Http/REST.php(58): Google_Task_Runner->run() #3 /opt/lampp/htdocs/api/vendor/google/apiclient/src/Google/Client.php(842): Google_Http_ in
}.................
I shall explain how to remove it.
Now delete “token.json”. Make sure to have backup of it.
Now, lets rerun it but on terminal.
Now they are asking for verification code, “paste that link in browser”.  They are telling us that “Now you are having access such as edit, delete, add in google calendar.”
Make sure that they are checked.
Copy the verification code, and paste it in terminal.
Now it says that “event is created. But in 2015”
I shall delete it for now.
And I shall make count as 1, so that “Event will be added one time only.”
As you can, see “displaying” and “adding” events are now working.
If you are smart enough, you can figure out “how to edit or delete event” all by yourself. I trust in you. All the best.
Thanks for watching.
Don’t forget to like, share and subscribe.

No comments:

Post a Comment