Skip to content

Oldes/Rebol-Google

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rebol-google

Rebol-Google CI Gitter Zulip

Rebol/Google

Google API integration module for Rebol3.

Usage:

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 location

or:

google: import google      ;; when the module is in the common modules location

It does not export any functions; instead, it currently contains the following API access points:

  • google/people to access user's Contacts
  • google/gmail to access Gmail mailboxes and send mail
  • google/photos to see, upload, and organize items in your Google Photos library
  • google/drive to 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:1d

Which 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.profile

List of all Google's OAuth2 scopes may be found here: https://developers.google.com/identity/protocols/oauth2/scopes

Useful examples

Check all user's shared drives for new content added since the previous day.

;; 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
]

About

A Google API module for Rebol3

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages