PC SOFT

ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Home | Sign in | English EN
  • Using GglConnect (from version 20 or from the update 19 - 89795)
GglConnect (Example)
Using GglConnect (from version 20 or from the update 19 - 89795)
This example is using the "OAuth 2.0" authentication mode.
googleConnection is gglConnection
googleConnection.Email = gsGoogleAccount
// in the following format: user_name@gmail.com
googleConnection.ClientID = gsGoogleClientID
// in the following format:
// 568705434218-sed6r7rgd7alcnbehs67f1k5s6ixqz84q.apps.googleusercontent.com
googleConnection.ClientSecret = gsGoogleClientSecret
// in the following format: kshKqXQPxUWmGLDiyBcmrCR2
// To create an ID and a Secret, you must:
// 1 - Own a Google account
// (not necessarily the one to which we connect,
// it will be the account associated with this application)
// 2 - Create a project in the Google console (https://code.google.com/apis/console)
// 3 - Create a project in the console by specifying the requested identifier
// (with the Google restrictions: between 6 and 30 characters, lowercase only, ...)
// note: it is not this identifier that will be used
// 4 - Select the project in the Google console and choose "Enable an API",
// and enable "Calendar API" (and "Contact API" if you are using the contacts)
// 5 - In the console, go to "Identifier" then "Create a client identifier",
// and "Application installed"
// ==> Google gives the identifier and the secret key
 
// Store and restore (if necessary) the connection information
// to avoid having to re-ask for the authorization at each connection
bufGoogleConnection is Buffer
sGoogleTokenFileName is string = fDataDir() + "\googletoken.bin"
 
// Was a connection stored beforehand?
IF fFileExist(sGoogleTokenFileName) THEN
// Restore the connection iwth its authorizations
// to avoid having to re-ask for the authorizations each time
WHEN EXCEPTION IN
Deserialize(googleConnection, fLLoadBuffer(sGoogleTokenFileName), psdBinary)
DO
// The deserialization failed,
// the file may be damaged
// => a new authentication request will be asked to the user
END
END
 
// Connect to the Google account
// ==> The first time, the user will have to validate an authentication window
IF NOT GglConnect(googleConnection, gglServiceCalendar) THEN
Error(ErrorInfo())
   // Deletes the file that contains the previous token
// (the connection failed: therefore the token is invalid)
IF fFileExist(sGoogleTokenFileName) THEN fDelete (sGoogleTokenFileName)
// Clears the gglConnection variable
// Note: you will need to assign a value again to
// the Email, ClientID and ClientSecret properties
// before re-establishing the connection
VariableReset(googleConnection)
ELSE
// Store the Google connection with the authorization information
Serialize(googleConnection, bufGoogleConnection, psdBinary)
fSaveBuffer(sGoogleTokenFileName, bufGoogleConnection)
 
// Retrieve the default calendar
ExistingCalendar is gglCalendar
ExistingCalendar = GglGetCalendar(googleConnection)
IF ErrorOccurred THEN
Error(ErrorInfo())
ELSE
Info("Calendar retrieved!")
END
END
Minimum version required
  • Version 14
This page is also available for…
Comments
Click [Add] to post a comment