Google API integration module for Rebol3.
To use this module, you need a Client ID and Secret for OAuth2 authentication.
Follow these steps to obtain them: https://support.google.com/googleapi/answer/6158849
The module stores these values in encrypted local storage.
If no user is set up yet, you will be prompted to provide a username, password for the local storage and the Client ID and Secret obtained from the Google Console.
A browser window will then open, where you'll need to choose a Google account and grant the required scopes for the script to access.
The module can be imported like any other Rebol module:
google: import %google.reb ;; when the module is in the current locationor:
google: import google ;; when the module is in the common modules locationIt does not export any functions; instead, it currently contains the following API access points:
google/peopleto access user's Contactsgoogle/gmailto access Gmail mailboxes and send mailgoogle/photosto see, upload, and organize items in your Google Photos librarygoogle/driveto access user's files (WIP)
Access points should be considered experimental shortcuts only and may be used, for example, like this:
data: google/people/contacts ;; resolves user's contacts data
foreach person data/connections [
if person/emailAddresses [
print [
as-green person/names/1/displayName
person/emailAddresses/1/value
]
]
]It is also possible to use direct API requests like:
data: google/api-get https://gmail.googleapis.com/gmail/v1/users/me/messages?q=newer_than:1dWhich is same like:
data: google/gmail [messages "newer_than:1d"]It should also be noted that the module, by default, expects only basic scopes. To access additional API functions, you may need to include the required scopes using the add-scope function. When scopes are modified, the token is dropped and the user must authenticate again!
google/add-acope https://www.googleapis.com/auth/userinfo.profile
;; which is same like:
google/add-scope @userinfo.profileList of all Google's OAuth2 scopes may be found here: https://developers.google.com/identity/protocols/oauth2/scopes
;; Turn off traces...
system/options/log/google: 0
;; Construct an object with query parameters used for all drives...
params: object [
query: ajoin [
"trashed=false AND createdTime > "
format-date-time now/date - 1 "'yyyy-MM-ddThh:mm:sZ'"
]
orderBy: 'createdTime
corpora: 'drive
driveId: none ;; will be set later
includeItemsFromAllDrives: true
supportsAllDrives: true
pageSize: 1000
fields: [id name parents mimeType webContentLink modifiedTime createdTime size sha256Checksum]
]
;; Check for new content in each drive...
foreach d google/drive/drives [
print-horizontal-line
print ["DRIVE:" d/name]
params/driveId: d/id
data: google/drive/files :params
?? data
save ajoin [%recent-data- d/name %.reb] data
]