ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Help / WLanguage / WLanguage functions / Communication / Drive functions
  • Overview
  • Prerequisite
  • How to?
  • Authentication
  • Manipulating drive files and directories
  • Special case: Manipulating files in Google Docs Editors
WINDEV
WindowsLinuxJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac Catalyst
Others
Stored procedures
Overview
There are many online storage services available. WINDEV, WEBDEV and WINDEV Mobile allow you to easily manipulate files on Dropbox, Google Drive and OneDrive. The code is the same regardless of the storage service used.
In Google Drive, you can also manipulate files from Google Docs Editors.
Prerequisite
To manipulate files, you need to configure the drives you want to use. For more details, see Prerequisites for using Google Drive, OneDrive and Dropbox.
How to?

Authentication

The use of these storage services requires authentication.
You can access the different services using OAuth 2.0.
To do so:
  1. Create a new OAuth2Parameters variable.
  2. Define the various properties of this variable, including:
    • ClientID: Client ID obtained when configuring the drive.
    • ClientSecret: Secret identifier obtained when configuring the drive.
    • RedirectionURL: Specify the desired URL, e.g. "http://localhost:9000".
  3. Create a variable of type Drive, and use the connection function for the desired service:
    dpDriveConnectCreates a connection to Dropbox.
    GglDriveConnectCreates a connection to Google Drive.
    oDriveConnectCreates a connection to OneDrive.
Note: It is also possible to pass a token with a refresh token. This solution avoids asking the user for login details again. The information to be used is detailed in the documentation of each connection function.
Examples:
  • Authenticating to Google Drive using the OAuth 2.0 protocol:
    // Authenticating to Google Drive using the OAuth 2.0 protocol
    oOAuth2Param is OAuth2Parameters
    oOAuth2Param.ClientID = "client_id"
    oOAuth2Param.ClientSecret = "client_secret"
    oOAuth2Param.RedirectionURL = "http://localhost:9000/"
     
    MyDrive is gglDrive
    MyDrive = GglDriveConnect(oOAuth2Param)
  • Authenticating to Google Drive using a token:
    // Authenticating to Google Drive using a token (refresh token)
    oOAuth2Param is OAuth2Parameters
    oOAuth2Param is OAuth2Parameters
    oOAuth2Param.ClientID = "client_id"
    oOAuth2Param.ClientSecret = "client_secret"
    oOAuth2Param.RedirectionURL = "http://localhost:9000/"
    
    oOAuth2Token is AuthToken
    oOAuth2Token = AuthIdentify(oOAuth2Param)
     
    MyDrive is gglDrive
    MyDrive = GglDriveConnect(oOAuth2Token)

Manipulating drive files and directories

The following functions are used to manipulate files and directories on a drive. All these functions use the Drive variable, which is specified during the authentication.

Special case: Manipulating files in Google Docs Editors

Google Drive allows users to manipulate files using Google Docs Editors: Docs, Sheets, Slides, etc.
These files must be manipulated using:
  • a variable of type gglDrive, which is the result of the GglDriveConnect function.
  • a variable of type GglFile, which allows you to manipulate files in the Google Docs Editors.
There are two specific functions for manipulating these files:
DriveDownloadGglFileDownloads a Google Docs Editors file from Google Drive in a given compatible format.
DriveListFileGglLists Google Docs Editors files (Docs, Sheets, etc.) present on Google Drive.
DriveListFileGgl gets the list of Google Docs Editors files on the drive. This function initializes the GglFile variable type. This variable type can then be used by the different Drive functions.
Example:
oOAuth2Param is OAuth2Parameters
oOAuth2Param.ClientID = "client_id"
oOAuth2Param.ClientSecret = "client_secret"
oOAuth2Param.RedirectionURL = "http://localhost:9000/"

gglMyDrive is gglDrive
gglMyDrive = GglDriveConnect(oOAuth2Param) 

arrGglFile is array of GglFile
arrGglFile = DriveListFileGgl(gglMyDrive, "/", frRecursive)

FOR EACH Queue OF arrGglFile
	SWITCH Queue.MimeType
		CASE mimeTypeGglDocs: Queue.ExportMimeType = mimeTypeDOCX
		CASE mimeTypeGglSheets: Queue.ExportMimeType = mimeTypeXLSX
		OTHER CASE: Queue.ExportMimeType = mimeTypePDF
	END 
	let ResDownload = DriveDownloadGglFile(gglMyDrive, arrGglFile[1], "c:\MyDocuments")
	IF ErrorOccurred THEN
		// Error handling
		Trace ("An error has occurred")
		RETURN
	END
END
Related Examples:
Drive functions Unit examples (WINDEV): Drive functions
[ + ] This example illustrates the use of Drive functions (Google Drive, Dropbox, OneDrive).
Drive functions Unit examples (WINDEV Mobile): Drive functions
[ + ] This example illustrates the use of Drive functions (Google Drive, Dropbox, OneDrive).
Minimum version required
  • Version 2024
This page is also available for…
Comments
Click [Add] to post a comment

Last update: 12/10/2024

Send a report | Local help