Monday 8 June 2020

Java Google Calendar API | Linux Terminal & Gradle Groovy | Display Events | Fix redirect_uri_mismatch



You can download library from:- https://unpossiblepog.com/research-and-development/GRADLE+JAVA/Google-Gradle-API-In-Java-For-Google-Drive-And-Google-Calendar

Please avoid or flag spams/hateful comments. And do not spam. Enjoy :)
------------------------------------------------

Official Google Developer page for google calendar JAVA API:-
https://developers.google.com/calendar/quickstart/java

Google Console  page:-
https://console.cloud.google.com/

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.
In this video, I shall make a connection between Google calendar and JAVA using gradle and display events in terminal or Command prompt.

Following operation requires Linux as it provides more flexibility for performing tasks.

Output can later be used in any framework like Spring, JSP, hibernate etc.

Lets go to google and search “google calendar quickstart java” go to developers.google.com link.

Requirements :
1. Google account with google calendar enabled.
2. Linux OS (debian family). I am using LUBUNTU. install linux in vmware or virtualbox if you don’t have LINUX as BOOT OS.
3. JAVA JDK version 1.8 or grater.
4. Then, gradle version greater than or equals to 2.3.



For people who doesn’t know what is gradle, in simple words, it is a build-tool which has 2 types, Groovy and Kotlin. And both of them can use any language Syntax for its script.
Kotlin is mostly used for android development and has file extension of .gradle.kts but groovy is mostly is used for webserver and with extension .gradle.

We are going to use groovy build and JAVA.

Then lets go to calendar.google.com and create an event. The red line is the current time so make the event after that line.

Now open file system. Create a folder in home with any name in my case “GoogleCalendar”.
Open that folder in terminal.

I already installed Java and gradle but still, show you the commands to install them.
Sometimes, you get older version of gradle, so you can upgrade it by using this command.
Then click on enable Google Calender API button.
Select Web server, now, type same url as I showed you. make sure that C in callback is capital.
Click on CREATE.
Download configuration.
Remember that file can be renamed if same file name already exists.

Now, in our newly created folder, create another folder with name CALLBACK. C capital.
Now in terminal, go inside callback folder using cd command.

Check if you have installed java and gradle correctly with required version.

Now, type the command they provided.

Type 1. To select Groovy.
For second question, don’t type anything, press enter directly.

Now if you check folder, some folders & files were automatically created.

Now paste the second command, which will create more folder in your project.

As per instructions, copy-paste credentials.json file from downloaded folder to this path.

Make sure to rename as credentials.json if name is different.

Next instruction is to copy-paste the gradle code in build.gradle file.

After that we have to create a java file at location as they told us.

Paste the code in it.

Here, remove “_READONLY” if you also want to change calendar events in future.

Now lets run the command “gradle run”.

It shall directly open the link in browser, but there is an error called “redirect_uri_mismatch”.

So to solve that, first cancel process by pressing ctrl+c in terminal.

Go to google console.

Left-top-menu, APIs & Services, and select credentials.

As you can see, the top Client Id is what we created on 7th of june, click on it, add URI, make sure to make same configuration as I do.

If you see in java code, the port number is 8888. So change that port in configuration.

Also, go to main callback folder and inside tokens folder, delete the file.
Lets clear the terminal and rerun the command.
It automatically opens the link in browser and you can see this page.
Select your google account,  click on advanced, go to quickstart unsafe, Allow.

You will see this message.
Now if you see it in terminal, you will see the upcoming event that we created at the beginning.
Lets rename it to verify. You can also create multiple events that will not be a problem for program to execute.

Now you can close terminal, and rename the folder.
Now open the renamed folder in terminal with same command and there will not be any problem in future.

In next tutorial, I shall show you how to get all events and display them on browser using JSP framework through gradle.

Required links are given in the description.
Don’t forget to like, share and subscribe.
Thanks for watching. 


No comments:

Post a Comment