ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Help / WLanguage / WLanguage functions / Communication / Google functions
  • Retrieving an event in a calendar
  • Retrieving a contact
GglRequest (Example)
Retrieving an event in a calendar
This example is used to perform a request in order to retrieve a specific event from a specific calendar.
googleConnection is gglConnection
googleConnection.Email = "username@gmail.com"
googleConnection.ClientID = ...
"568705434218-sed6r7rgd7alcnbehs67f1k5s6i4q.apps.googleusercontent.com"
googleConnection.ClientSecret = "kshKqXQPxUWmGLDiyBcmrCR2"
 
// Connect to the Google account
IF NOT GglConnect(googleConnection, ...
gglServiceCalendar + gglServiceContacts) THEN
Error(ErrorInfo())
RETURN
ELSE
// Connected
// to perform a request that retrieves a specific event from a specific calendar
 
// 1 - An identifier of Google calendar is required
sCalendarID is string
arrCalendar is array of gglCalendars
arrCalendar = GglListCalendar(googleConnection, gglAll)
aCalendar is gglCalendar
FOR EACH aCalendar OF arrCalendar
IF aCalendar.Title = "Title of sought calendar" THEN
sCalendarID = aCalendar.Identifier
// Value of the type: gi57430lh5j58ddife6nmbqilk@group.calendar.google.com
BREAK
END
END
IF sCalendarID = "" THEN
Info("Calendar not found")
RETURN
END
 
// 2 - An identifier of Google event is required
sEventID is string = "5lq85na71prritap8llpoo5cl8_20150107T070000Z"
// This identifier must have been initially retrieved
// from a gglEvent variable
// (via the Identifier property)
 
// 3 - Starts the Google request
// Information about the possibilities of Google requests
// in the Google documentation on 01/01/2015:
// https://developers.google.com/google-apps/calendar/v3/reference/events
// - Perform a GET request on:
// https://www.googleapis.com/calendar/v3/calendars/<calendarId>/events/<eventId>
// - Parameters (optional): alwaysIncludeEmail, timeZone, maxAttendees,
// Name of the controls to include
sResponseJsonGgl is string
sResponseJsonGgl = GglRequest(googleConnection, ...
gglServiceCalendar,... //Request to the Calendar service
"https://www.googleapis.com/calendar/v3/calendars/" + ...
URLEncode(sCalendarIE) + "/events/" + URLEncode(sEventID), ... // URL
"alwaysIncludeEmail=true&timeZone="+ ...
"Europe/Paris&maxAttendees=10", ...//Parameters (optional)
gglHTTPGet) // HTTP Get request
 
// Error or non-JSON response from Google
IF ErrorOccurred _OR_ NoSpace(sResponseJsonGgl)[[1]] <>"{" THEN
Error("Failure retrieving the event", ...
sResponseJsonGgl, ErrorInfo())
RETURN
END
 
// Automatic retrieval in a variant
let strGoogleResponse =JSONToVariant(sResponseJsonGgl)
// or retrieval in a structure described beforehand (on 01/01/2015 in this case:
// https://developers.google.com/google-apps/calendar/v3/reference/events)
// strGoogleEvent is STgglEvents
// Deserialize(strGoogleEvent,sResponseJsonGgl,psdJSON)
 
Info("Event of " + StringToDate(strGoogleResponse.start.dateTime[[TO 10]], ...
"YYYY-MM-DD") + StringToTime(strGoogleResponse.start.dateTime[[12 TO 19]],...
"HH:MM:SS")+...//format: 2014-11-25T14:00:00+01:00
" at " + StringToDate(strGoogleResponse.end.dateTime[[TO 10]],"YYYY-MM-DD") + ...
StringToTime(strGoogleResponse.end.dateTime[[12 TO 19]],...
"HH:MM:SS"),...//format: 2014-11-25T15:30:00+01:00
"Created by: " + strGoogleResponse.creator.email, ...
"Title: " + strGoogleResponse.summary, ...
"Details: " + strGoogleResponse.description, ...
"Update: " + strGoogleResponse.updated)
END
Retrieving a contact
This example is used to perform a request in order to retrieve a contact with all the details including the full address.
googleConnection is gglConnection
googleConnection.Email = "username@gmail.com"
googleConnection.ClientID = ...
"568705434218-sed6r7rgd7alcnbehs67f1k5s6ixqz84q.apps.googleusercontent.com"
googleConnection.ClientSecret = "kshKqXQPxUWmGLDiyBcmrCR2"
 
// Connect to the Google account
IF NOT GglConnect(googleConnection, gglServiceContacts) THEN
Error(ErrorInfo())
RETURN
ELSE
// Connected
// to perform a request that retrieves a specific contact from a Google account
// 1 - A Google account is required
sGoogleAccount is string = googleConnection.Email // or "default"
 
// 2 - Then, a contact identifier is required
googleContact is gglContact
// GglListContactByRequest(
// The first contact
aaContactGGl is array of gglContacts = GglListContact(googleConnection)
googleContact = aaContactGGl[1]
// the last section of the identifier only
sGoogleContactID is string = ExtractString(googleContact.Identifier, ...
1, "/", FromEnd)
 
//3 - Starts the Google request
// Information about the possibilities of Google requests
// in the Google documentation on 01/01/2015:
// https://developers.google.com/google-apps/contacts/v3/index#retrieving_a_single_contact
// - Perform a POST request on:
// https://www.google.com/m8/feeds/contacts/<CompteId>/<full/<ContactID>
// - Parameters (optional):
// v=3.0 to get the full details,
// and alt=json to get the result in json and not in xml
sResponseJsonGgl is string
sResponseJsonGgl = GglRequest(googleConnection, ...
gglServiceContacts, ...// Request to the Calendar service
"https://www.google.com/m8/feeds/contacts/" + URLEncode(sGoogleAccount) + ...
"/full/" + URLEncode(sGoogleContactID)+"?v=3.0&alt=json", ... // URL
"", ... //Parameters (optional)
gglHTTPGet) // HTTP Get request
// Error or non-Json response from Google?
IF ErrorOccurred _OR_ NoSpace(sResponseJsonGgl)[[1]] <> "{" THEN
Error("Failure retrieving the event", sResponseJsonGgl, ErrorInfo())
RETURN
END
// Retrieve Json in a structure
// (see https://developers.google.com/google-apps/contacts/v3/reference)
let strGoogleResponse = JSONToVariant(sResponseJsonGgl)
 
Info("Title: " + strResponseJsonGgl.entry.gd$name.gd$namePrefix.$t, ...
"First name: " + strResponseJsonGgl.entry.gd$name.gd$givenName.$t, ...
"Last name: " + strResponseJsonGgl.entry.gd$name.gd$familyName.$t, ...
"Suffix: " + strResponseJsonGgl.entry.gd$name.gd$nameSuffix, ...
"Additional first name: " + strResponseJsonGgl.entry.gd$name.gd$additionalName.$t, ...
"Street: " + strResponseJsonGgl.entry.gd$structuredPostalAddress[1].gd$street.$t, ...
"Neighborhood: " + ...
strReponseJsonGgl.entry.gd$structuredPostalAddress[1].gd$neighborhood.$t, ...
"Postal box: " + strResponseJsonGgl.entry.gd$structuredPostalAddress[1].gd$pobox.$t, ...
"Zip code: " + strResponseJsonGgl.entry.gd$structuredPostalAddress[1].gd$postcode.$t, ...
"City: " + strResponseJsonGgl.entry.gd$structuredPostalAddress[1].gd$city.$t, ...
"Region: " + strResponseJsonGgl.entry.gd$structuredPostalAddress[1].gd$region.$t, ...
"Country: " + strResponseJsonGgl.entry.gd$structuredPostalAddress[1].gd$country.$t)
END
Minimum version required
  • Version 14
This page is also available for…
Comments
Click [Add] to post a comment

Last update: 05/26/2022

Send a report | Local help