B4J Library GoogleCalendar - GCal4J

GCal4J
<link>...|https://www.b4x.com</link>
Author: DonManfred
Version: 0.26
  • Calendar
    • Functions:
      • IsInitialized As Boolean
    • Properties:
      • CalendarList As com.google.api.services.calendar.Calendar.CalendarList [read only]
      • Calendars As com.google.api.services.calendar.Calendar.Calendars [read only]
      • Channels As com.google.api.services.calendar.Calendar.Channels [read only]
      • Colors As com.google.api.services.calendar.Calendar.Colors [read only]
      • Events As com.google.api.services.calendar.Calendar.Events [read only]
      • RootUrl As String [read only]
  • CalendarList
    • Functions:
      • Delete (calendarId As String)
      • Get (calendarId As String) As com.google.api.services.calendar.model.CalendarListEntry
      • Insert (content As com.google.api.services.calendar.model.CalendarListEntry) As com.google.api.services.calendar.model.CalendarListEntry
      • IsInitialized As Boolean
      • Update (calendarId As String, content As com.google.api.services.calendar.model.CalendarListEntry) As com.google.api.services.calendar.model.CalendarListEntry
    • Properties:
      • Items As java.util.List [read only]
  • CalendarListEntry
    • Functions:
      • IsInitialized As Boolean
    • Properties:
      • AccessRole As String [read only]
      • BackgroundColor As String [read only]
      • Deleted As Boolean [read only]
      • Description As String [read only]
      • Etag As String
      • ForegroundColor As String [read only]
      • Hidden As Boolean [read only]
      • Id As String [read only]
      • Kind As String [read only]
      • Location As String [read only]
      • Primary As Boolean [read only]
      • Selected As Boolean [read only]
      • Summary As String [read only]
      • TimeZone As String [read only]
  • Calendars
    • Functions:
      • clear (calendarId As String)
      • delete (calendarId As String)
      • IsInitialized As Boolean
  • Event
    • Functions:
      • GetField (fieldName As String) As Object
      • GetKeySet
      • Initialize
      • IsInitialized As Boolean
      • setEnd (endtime As Long, timezone As String)
      • SetField (fieldName As String, value As Object)
      • setStart (starttime As Long, timezone As String)
    • Properties:
      • Attachments As java.util.List
      • Attendees As java.util.List
      • ColorId As String
      • Created As Long [read only]
      • Description As String
      • End As Long [read only]
      • Etag As String
      • HtmlLink As String
      • ICalUID As String [read only]
      • Id As String
      • Location As String
      • Locked As Boolean
      • Recurrence As java.util.List
      • Start As Long [read only]
      • Status As String
      • Summary As String
      • Updated As Long
  • EventReminder
    • Functions:
      • clear
      • Initiallize
      • IsInitialized As Boolean
    • Properties:
      • Method As String
      • Minutes As Int
  • EventReminders
    • Functions:
      • clear
      • Initiallize
      • IsInitialized As Boolean
    • Properties:
      • Overrides As java.util.List
      • UseDefault As Boolean
  • Events
    • Functions:
      • Delete (calendarId As String, eventId As String)
      • Get (calendarId As String, eventId As String) As com.google.api.services.calendar.model.Event
      • Insert (calendarId As String, content As com.google.api.services.calendar.model.Event) As com.google.api.services.calendar.model.Event
      • IsInitialized As Boolean
      • List (calendarId As String) As java.util.List
      • Update (calendarId As String, eventId As String, content As com.google.api.services.calendar.model.Event) As com.google.api.services.calendar.model.Event
  • GoogleCalendar
    • Functions:
      • Initialize (EventName As String, applicationName As String, clientId As String, clientSecret As String, refreshToken As String, accessToken As String)
      • makeClient (clientId As String, clientSecret As String, applicationName As String, emailAddress As String, p12FileName As String, user As String, refreshToken As String, accessToken As String) As com.google.api.services.calendar.Calendar
    • Properties:
      • Calendar As com.google.api.services.calendar.Calendar [read only]
      • CalendarList As com.google.api.services.calendar.Calendar.CalendarList [read only]
      • Calendars As com.google.api.services.calendar.Calendar.Calendars [read only]
      • Events As com.google.api.services.calendar.Calendar.Events [read only]

The Library depends on a lot of jars. You can download them here:


B4X:
    oauth2.GetAccessToken
    Wait For OAuth2_AccessTokenAvailable (Success As Boolean, token As String)
    If Success = False Then
        Log("Error accessing account.")
        Return
    Else
        Log($"Success = ${Success}"$)
        Log($"Token = ${token}"$)
'        kvs.Put("Token",token)   
        GCal.Initialize("Calendar","GCal",ClientId,ClientSecret,Null,token)
        
        Dim c As Calendar = GCal.Calendar
        Log("Calendar Object")
        Log(c)
        Log(c.RootUrl)
        events = c.Events ' events is a global Var.
        '                   Once set you can use it for further operations.
        '                   It is a important Object...
        Log("Events Object")
        Log(events)
        

        Log("CalendarList")
        Dim cl As CalendarList =  GCal.calendarList
        Log(cl)
        Dim calendarslist As List =  cl.Items
        If calendarslist <> Null And calendarslist.IsInitialized And calendarslist.Size > 0 Then
            For i=0 To calendarslist.Size-1
                Dim entry As CalendarListEntry = calendarslist.Get(i)
                Log($"=========== CALENDAR ==========================="$)
                Log(entry.Etag)
                Log(entry.Id)

                'If entry.Id.Contains("xxxxx") Then ' work with the Calendar you want to
                    
                    Dim eventslist As List = events.List(entry.Id) ' Get all Events from the given Calendar.
                    If eventslist.IsInitialized And eventslist.Size>0 Then
                        Log("Events "&entry.Id)
                        Log(eventslist.Size)
                        For o= 0 To eventslist.Size-1
                            Log($"=========== EVENT ==========================="$)
                            Dim event As Event = eventslist.Get(o)
                            Log(event)
                            Log(event.Id)
                            Log(event.Description)
                            Log(event.Location)
                            Log(event.Start)
                            Log(event.End)
                            Log(event.Etag)
                        Next
                    End If
                    'events
               ' End If
            Next
        End If
    End If
 

Attachments

  • GoogleCalendarEx.zip
    6.1 KB · Views: 569
  • GCal4JV0.26.zip
    46.3 KB · Views: 547

DonManfred

Expert
Licensed User
Longtime User
You need to have it running at least. See the Example.
As mentioned the Events Object is a Important one.
It is basically the Bridge to Get an Event, Update an Event or Inserting a Event. Even Deleting.

Inserting a New Event
===================
B4X:
                                Dim event As Event
                                event.Initialize
                                event.Location = "Somewhere over the Rainbow"
                                event.Description = "Event description here...."
                                event.Summary = "Summary"
                                
                                Dim oldformatD As String = DateTime.DateFormat
                                DateTime.DateFormat = "dd.MM.yyyy"
                                Dim oldformatT As String = DateTime.TimeFormat
                                DateTime.TimeFormat = "HH:mm"
                                
                                Dim dtstart As Long = DateTime.DateTimeParse(rsevents.GetString("event_date"),rsevents.GetString("event_time"))
                                event.setStart(dtstart,"Europe/Berlin")
                                Dim dtend As Long = DateTime.DateTimeParse(rsevents.GetString("event_date"),rsevents.GetString("event_time"))
                                event.setEnd(dtend,"Europe/Berlin")
                                DateTime.DateFormat = oldformatD
                                DateTime.TimeFormat = oldformatT

                                Log(rs.GetString("s_googleAccount"))
                                Log($"GoogleID Event vor Insert = ${event.Id}"$)
                                event = events.Insert(rs.GetString("s_googleAccount"),event)
                               ' Note that event NOW has a ID. Store it for further references. For ex. if you want to Delete or Update an Event.
                                Log($"GoogleID Event = ${event.Id}"$)

Update a Existing Event.
==================

B4X:
Dim event As Event = events.Get("calendarID","eventid")
' Now work with event. Changing Start, End, Location, Description, Summary.
'
' Next step is to save the edited Event back to Google.
Dim updated As Event = events.Update("calendarID","eventid",event)
'
 
Hi everyone,

when I try to start the example project I get the error:
"
Error
javac 1.8.0_251
src\b4j\example\main.java:60: error: cannot access GoogleCalendarAdmin
public static de.donmanfred.GoogleCalendarAdmin _gcal = null;
^
bad class file: C:\Program Files (x86)\Anywhere Software\B4J\libraries\gcal4j.jar(de/donmanfred/GoogleCalendarAdmin.class)
class file has wrong version 55.0, should be 52.0
Please remove or make sure it appears in the correct subdirectory of the classpath.
"

The b4j version is the latest, and I haven't found any other gcal4j version.
Can someone help me?
Thank you
 

miga

Member
Licensed User
Longtime User
Hi guys,

I'm playing with this and everything seams to work. But if I want to add another library (or unselect and re-select existing library) all project stops to work. The events doesn't work anymore (no properties available only Consumed and IsInitialize)
1618318034391.png
.
I can do anything, but it doesn't work. I have to unzip the project again (or copy/past original b4j file) to test it again.
Is the project somehow locked against changes?
As I wrote, this happened when I do any change in library list.
 

DonManfred

Expert
Licensed User
Longtime User
I'm playing with this and everything seams to work. But if I want to add another library (or unselect and re-select existing library) all project stops to work. The events doesn't work anymore (no properties available only Consumed and IsInitialize)
1. Create a NEW THREAD for any Question/Issue you have. ADD ALL RELEVANT INFO; add a testprojectupload.
2. What is the content of the Image?

I don´t understand anthing from your post.
 

amorosik

Expert
Licensed User
Could you indicate how to obtain the necessary data to authenticate on the Google Calendar api?
I ask this because I have activated a developer account, but even when I was looking I could not figure out where to find the information needed to run the program described in this thread
 

amorosik

Expert
Licensed User
This link for access to Google Calendar credential

Go to https://console.developers.google.com/ to obtain your google credentials.
You must go to the Library and select the Google Calendar API.
Under the Credentials section, you must assign a project name (what ever you want to call it) and create credentials.
There you will find you client_id and client_secret.
 
Top