VB icon

List all entries of your Google calendar on a specific date

Email
Submitted on: 10/23/2016 11:44:34 AM
By: John Anast 
Level: Advanced
User Rating: Unrated
Compatibility: VB.NET
Views: 1582
 
     With this code you can get all events on a specific date of your google calendar account. With a litle editing you can make it a range of dates. You must have a google API_key and OATH2 Client_ID and Secret (you can get them free on Goole when enabling google API. You should create a form with a datetimepicer1 control and a listbox1 Also, you must have isntalled Google Calendar API v3 in your application developement In packet manager the command to do it is PM>install-package Google.Apis.Calendar.V3
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
//**************************************
// Name: List all entries of your Google calendaron a specific date
// Description:With this code you can get all events on a specific date of your google calendar account. With a litle editing you can make it a range of dates. You must have a google API_key and OATH2 Client_ID and Secret (you can get them free on Goole when enabling google API.
You should create a form with a datetimepicer1 control and a listbox1
Also, you must have isntalled Google Calendar API v3 in your application developement
In packet manager the command to do it is
PM>install-package Google.Apis.Calendar.V3
// By: John Anast
//**************************************

Imports System.IO
Imports System.Data.SqlClient
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.ComponentModel
Imports Google.Apis.Auth.OAuth2
Imports Google.Apis.Services
Imports System.Collections.Generic
Imports Google.Apis.Calendar.v3
Imports Google.Apis.Calendar.v3.Data
Imports Google.Apis.Calendar.v3.Data.Event
Imports Google.Apis.Util.Store
Imports Google.Apis.Calendar.v3.EventsResource
Imports System.Threading
 Private Sub DateTimePicker1_ValueChanged(sender As Object, e As EventArgs) Handles DateTimePicker1.ValueChanged
Me.UseWaitCursor = True
Dim gg As String
"Making data value a string that contains only date
gg = Format(DateTimePicker1.Value, "yyyy-MM-dd")
Dim service As CalendarService
Dim scopes As IList(Of String) = New List(Of String)
Dim initializer = New BaseClientService.Initializer
Try
scopes.Add(CalendarService.Scope.Calendar)
Dim Secrets = New ClientSecrets()
Secrets.ClientId = "<<<<<<<<<<<<<<<<ENTER YOUR CLIENT ID HERE>>>>>>>>>>>"
Secrets.ClientSecret = "<<ENTER OUR CLIENT SECRET HERE>>>"
Dim scope = New List(Of String)
scope.Add(CalendarService.Scope.Calendar)
Dim credential = GoogleWebAuthorizationBroker.AuthorizeAsync(Secrets, scopes, "ENTER YOUR GOOGLE ACCOUNT USERNAME", CancellationToken.None).Result()
'Dim initializer = New BaseClientService.Initializer
initializer.HttpClientInitializer = credential
initializer.ApplicationName = "THE APP NAME YOU DECLARED IN GOOGLE API"
service = New CalendarService(initializer)
Dim list As IList(Of CalendarListEntry) = service.CalendarList.List().Execute().Items
Dim requeust As ListRequest = service.Events.List("dentalan@gmail.com")
requeust.TimeMax = gg + "T23:59:59"
requeust.TimeMin = gg + "T00:00:00"
requeust.Fields = "items(end,start,summary)" 'You can comment it to have all fields
requeust.SingleEvents = True
requeust.OrderBy = ListRequest.OrderByEnum.StartTime
Dim p As Object
p = requeust.Execute.Items
ListBox1.Items.Clear()
If p.count = 0 Then
ListBox1.Items.Add("No events Today")
Else
For i = 0 To requeust.Execute.Items.Count - 1
ListBox1.Items.Add(Format(p(i).Start.DateTime, "hh:mm") & "-" & Format(p(i).End.DateTime, "hh:mm") & " " & p(i).Summary)
Next i
End If
Catch ex As Exception
MsgBox(ex.ToString)
End Try
Me.UseWaitCursor = False
End Sub


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Advanced category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments

10/23/2016 7:29:33 PMJohn Anast

Please change the line
Dim requeust As ListRequest = service.Events.List("dentalan@gmail.com")
to
Dim requeust As ListRequest = service.Events.List("primary")
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.