|
|
|
|
- Overview
- Prerequisite
- How to?
- Authentication
- Manipulating drive files and directories
- Special case: manipulating files in Google Docs Editors
Manipulating files in Dropbox, Google Drive and OneDrive
Not available
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. Authentication The use of these storage services requires authentication. You can access the different services using OAuth 2.0. To do so: - Create a new OAuth2Parameters variable.
- 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:29000".
- Create a variable of type Drive, and use the connection function for the desired service:
| | | Creates a connection to Dropbox. | | Creates a connection to Google Drive. | | Creates a connection to OneDrive. |
Remark: 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:
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:
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. - File manipulation functions:
| | | Copies a single file on a remote drive to another directory on same drive. | | Creates a file on the remote drive. | | Deletes a file from a remote drive. | | Downloads a file from a remote drive to the user's computer. | | Lists the files in a cloud-based drive directory. | | Moves a file on a remote drive from one directory to another. | | Renames a file or directory on a remote drive. | | Uploads a local file to a remote drive. |
- Directory manipulation functions:
| | | Copies a directory on a remote drive to another directory. | | Creates a directory on the remote drive. | | Deletes a directory and its files from a remote drive. | | Downloads a directory and its files from a remote drive to the user's computer. | | Lists drive directories. | | Moves a directory and its contents to another directory within a remote drive. | | Renames a file or directory on a remote drive. | | Uploads a directory and its contents to a remote drive. |
Special case: manipulating files in Google Docs Editors Google Drive allows users to manipulate files using the 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: | | | Downloads a Google Docs Editors file from Google Drive in a given compatible format. | | Lists 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
Trace ("An error has occurred")
RETURN
END
END
Related Examples:
|
Unit examples (WINDEV): Drive functions
[ + ] This example illustrates the use of Drive functions (Google Drive, Dropbox, OneDrive).
|
|
Unit examples (WINDEV Mobile): Drive functions
[ + ] This example illustrates the use of Drive functions (Google Drive, Dropbox, OneDrive).
|
This page is also available for…
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|