Class GoogleAPITool


  • public class GoogleAPITool
    extends java.lang.Object
    Google API toolbox
    This class only provides static variables and methods
    • Method Summary

      All Methods Static Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      static com.google.api.client.auth.oauth2.Credential authorize​(java.lang.String userId, java.lang.String json, java.util.Collection<java.lang.String> scopes)
      EXPERIMENTAL Authorizes application to access user's protected data.
      static com.google.api.services.drive.model.About driveAbout​(com.google.api.services.drive.Drive drive, java.lang.String fields)
      Get drive about for specified fields
      static com.google.api.services.drive.model.File driveCreate​(com.google.api.services.drive.Drive drive, java.lang.String name, java.lang.String mime, byte[] data)
      Create drive file (override)
      static com.google.api.services.drive.model.File driveCreate​(com.google.api.services.drive.Drive drive, java.lang.String name, java.lang.String mime, byte[] data, java.lang.String folderId, boolean override)
      Create drive file
      static com.google.api.services.drive.model.File driveCreate​(com.google.api.services.drive.Drive drive, java.lang.String name, java.lang.String mime, java.io.InputStream in)
      Create drive file (override)
      static com.google.api.services.drive.model.File driveCreate​(com.google.api.services.drive.Drive drive, java.lang.String name, java.lang.String mime, java.io.InputStream in, java.lang.String folderId, boolean override)
      Create drive file
      static com.google.api.services.drive.model.File driveCreateFolder​(com.google.api.services.drive.Drive drive, java.lang.String name, java.lang.String parentId, boolean unique)
      Create a drive folder
      static com.google.api.services.drive.model.Permission driveCreatePermissionAnyone​(com.google.api.services.drive.Drive drive, java.lang.String fileId, boolean canWrite)
      Add file permission to anyone
      static com.google.api.services.drive.model.Permission driveCreatePermissionAnyone​(com.google.api.services.drive.Drive drive, java.lang.String fileId, boolean canWrite, boolean notif)
      Add file permission to anyone
      static com.google.api.services.drive.model.Permission driveCreatePermissionDomain​(com.google.api.services.drive.Drive drive, java.lang.String fileId, java.lang.String domain, boolean canWrite)
      Add file permission to domain
      static com.google.api.services.drive.model.Permission driveCreatePermissionDomain​(com.google.api.services.drive.Drive drive, java.lang.String fileId, java.lang.String domain, boolean canWrite, boolean notif)
      Add file permission to domain
      static com.google.api.services.drive.model.Permission driveCreatePermissionGroup​(com.google.api.services.drive.Drive drive, java.lang.String fileId, java.lang.String email, boolean canWrite)
      Add file permission to group (same as user)
      static com.google.api.services.drive.model.Permission driveCreatePermissionGroup​(com.google.api.services.drive.Drive drive, java.lang.String fileId, java.lang.String email, boolean canWrite, boolean notif)
      Add file permission to group (same as user)
      static com.google.api.services.drive.model.Permission driveCreatePermissionUser​(com.google.api.services.drive.Drive drive, java.lang.String fileId, java.lang.String email, boolean canWrite)
      Add file permission to user
      static com.google.api.services.drive.model.Permission driveCreatePermissionUser​(com.google.api.services.drive.Drive drive, java.lang.String fileId, java.lang.String email, boolean canWrite, boolean notif)
      Add file permission to user
      static void driveDelete​(com.google.api.services.drive.Drive drive, java.lang.String fileId)
      Delete drive file
      static void driveDeletePermission​(com.google.api.services.drive.Drive drive, java.lang.String fileId, java.lang.String permissionId)
      Remove file permission
      static com.google.api.services.drive.model.File driveGet​(com.google.api.services.drive.Drive drive, java.lang.String fileId, java.lang.String fields)
      Get drive file
      static java.util.List<com.google.api.services.drive.model.File> driveList​(com.google.api.services.drive.Drive drive, java.lang.String query)
      List drive files from query
      static java.util.List<com.google.api.services.drive.model.File> driveList​(com.google.api.services.drive.Drive drive, java.lang.String query, java.lang.String fields)
      List drive files from query
      static java.util.List<com.google.api.services.drive.model.File> driveListFolder​(com.google.api.services.drive.Drive drive, java.lang.String query, java.lang.String folderId)
      List drive files in a folder
      static java.util.List<com.google.api.services.drive.model.File> driveListFolder​(com.google.api.services.drive.Drive drive, java.lang.String query, java.lang.String folderId, java.lang.String fields, boolean trashed)
      List drive files in a folder
      static java.util.List<com.google.api.services.drive.model.Permission> driveListPermissions​(com.google.api.services.drive.Drive drive, java.lang.String fileId)
      List all permissions on file
      static com.google.api.services.drive.model.File driveMove​(com.google.api.services.drive.Drive drive, java.lang.String fileId, java.lang.String folderId)
      Move a file to folder
      static java.lang.String driveQueryString​(java.lang.String value)
      Prepare a string for a drive query.
      static com.google.api.services.drive.model.About.StorageQuota driveStorageQuota​(com.google.api.services.drive.Drive drive)
      Get drive storage quota
      static com.google.api.services.drive.model.File driveUpdate​(com.google.api.services.drive.Drive drive, java.lang.String fileId, java.lang.String name, java.lang.String mime, byte[] data)
      Update a file in drive
      static com.google.api.services.drive.model.File driveUpdate​(com.google.api.services.drive.Drive drive, java.lang.String fileId, java.lang.String name, java.lang.String mime, java.io.InputStream in)
      Update a file in drive
      static java.lang.String getAPIKey​(Grant g)
      Get API key
      static com.google.api.services.calendar.Calendar getCalendarService​(com.google.api.client.auth.oauth2.Credential credential)
      Get Calendar service
      static com.google.api.services.calendar.Calendar getCalendarService​(Grant g)
      Get Calendar service
      static com.google.api.services.calendar.Calendar getCalendarService​(java.lang.String json)
      Get Calendar service
      static com.google.api.client.auth.oauth2.Credential getCredential​(Grant g)
      Get Google credential object from access token
      static com.google.api.client.auth.oauth2.Credential getCredential​(java.lang.String accessToken)
      Get Google credential object from access token
      static com.google.api.client.auth.oauth2.Credential getCredentialAccount​(java.lang.String key)
      Get Google credential from service account
      static java.lang.String getDriveFileURL​(java.lang.String fileId)
      URL to open file in drive
      static java.lang.String getDriveFolderURL​(java.lang.String folderId)
      URL to open folder in drive
      static com.google.api.services.drive.Drive getDriveService​(com.google.api.client.auth.oauth2.Credential credential)
      Get Drive service for the platform name
      static com.google.api.services.drive.Drive getDriveService​(com.google.api.client.auth.oauth2.Credential credential, java.lang.String appName)
      Get Drive service
      static com.google.api.services.drive.Drive getDriveService​(Grant g)
      Get Drive service
      static com.google.api.services.drive.Drive getDriveService​(java.lang.String json)
      Get Drive service
      static java.lang.String getFontCSS​(java.lang.String font)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Use HTMLTool.getGoogleFontCSS
      static java.lang.String getFontName​(Grant g)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Use HTMLTool.getGoogleFontName
      static java.lang.String getFontURL​(java.lang.String font)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Use HTMLTool.getGoogleFontURL
      static com.google.api.services.gmail.Gmail getGmailService​(com.google.api.client.auth.oauth2.Credential credential)
      Get Gmail service
      static com.google.api.services.gmail.Gmail getGmailService​(Grant g)
      Get Gmail service
      static com.google.api.services.gmail.Gmail getGmailService​(java.lang.String json)
      Get Gmail service
      static java.lang.String getLoginURL​(java.lang.String client_id, java.lang.String redirect_uri, java.lang.String login_hint, java.lang.String scopes, java.lang.String state)
      Get the URL of Google OAuth2 login page
      static com.google.api.services.plus.Plus getPlusService​(com.google.api.client.auth.oauth2.Credential credential)
      Deprecated, for removal: This API element is subject to removal in a future version. 
      static com.google.api.services.plus.Plus getPlusService​(Grant g)
      Deprecated, for removal: This API element is subject to removal in a future version. 
      static com.google.api.services.plus.Plus getPlusService​(java.lang.String json)
      Deprecated, for removal: This API element is subject to removal in a future version. 
      static com.google.api.services.sheets.v4.Sheets getSheetsService​(com.google.api.client.auth.oauth2.Credential credential)
      Get Sheets service
      static com.google.api.services.sheets.v4.Sheets getSheetsService​(Grant g)
      Get Sheets service
      static com.google.api.services.sheets.v4.Sheets getSheetsService​(java.lang.String json)
      Get Sheets service
      static java.lang.String getToken​(Grant g)
      Get token (and refresh it if needed)
      static org.json.JSONObject getToken​(java.lang.String client_id, java.lang.String client_secret, java.lang.String redirect_uri, java.lang.String code)
      Get token
      static com.google.api.services.translate.Translate getTranslateService​(Grant g)
      Get Translate service
      static com.google.api.services.translate.Translate getTranslateService​(java.lang.String apiKey)
      Get Translate service
      static org.json.JSONObject getUserData​(java.lang.String token)
      Get user data
      static com.google.api.services.youtube.YouTube getYouTubeService​(com.google.api.client.auth.oauth2.Credential credential)
      Get YouTube service
      static com.google.api.services.youtube.YouTube getYouTubeService​(Grant g)
      Get YouTube service
      static com.google.api.services.youtube.YouTube getYouTubeService​(java.lang.String json)
      Get YouTube service
      static com.google.api.services.plus.model.Activity plusGetActivity​(com.google.api.services.plus.Plus plus, java.lang.String activityId)
      Deprecated, for removal: This API element is subject to removal in a future version. 
      static com.google.api.services.plus.model.Person plusGetMe​(com.google.api.services.plus.Plus plus)
      Deprecated, for removal: This API element is subject to removal in a future version. 
      static com.google.api.services.plus.model.Person plusGetPerson​(com.google.api.services.plus.Plus plus, java.lang.String userId)
      Deprecated, for removal: This API element is subject to removal in a future version. 
      static java.util.List<com.google.api.services.plus.model.Activity> plusGetPublicActivities​(com.google.api.services.plus.Plus plus, java.lang.String userId)
      Deprecated, for removal: This API element is subject to removal in a future version. 
      static java.util.List<com.google.api.services.plus.model.Activity> plusSearchActivities​(com.google.api.services.plus.Plus plus, java.lang.String query, long maxResults)
      Deprecated, for removal: This API element is subject to removal in a future version. 
      static java.util.List<com.google.api.services.plus.model.Person> plusSearchPersons​(com.google.api.services.plus.Plus plus, java.lang.String query, long maxResults)
      Deprecated, for removal: This API element is subject to removal in a future version. 
      static org.json.JSONObject refreshToken​(java.lang.String clientId, java.lang.String clientSecret, java.lang.String refreshToken)
      Refresh token
      static boolean revokeToken​(java.lang.String token)
      Revoke a Google OAuth2 token
      static java.lang.String translate​(com.google.api.services.translate.Translate service, java.lang.String text, java.lang.String source, java.lang.String target)
      Traslate
      static java.lang.String[] translate​(Grant g, java.lang.String text, java.lang.String source, java.lang.String target)
      Translate text to specified language
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • API_KEY_NAME

        public static final java.lang.String API_KEY_NAME
        Google API key system parameter name
        See Also:
        Constant Field Values
      • SCOPE_PROFILE

        public static final java.lang.String SCOPE_PROFILE
        Profile scope
        See Also:
        Constant Field Values
      • SCOPE_EMAIL

        public static final java.lang.String SCOPE_EMAIL
        Email scope
        See Also:
        Constant Field Values
      • SCOPE_OPENID

        public static final java.lang.String SCOPE_OPENID
        OpenIDConnect scope
        See Also:
        Constant Field Values
      • USERINFO_PROFILE_SCOPE

        public static final java.lang.String USERINFO_PROFILE_SCOPE
        User info profile scope
        See Also:
        Constant Field Values
      • USERINFO_EMAIL_SCOPE

        public static final java.lang.String USERINFO_EMAIL_SCOPE
        User info email scope
        See Also:
        Constant Field Values
      • PLUS_LOGIN_SCOPE

        public static final java.lang.String PLUS_LOGIN_SCOPE
        Google+ scope
        See Also:
        Constant Field Values
      • PLUS_ME_SCOPE

        public static final java.lang.String PLUS_ME_SCOPE
        Google Me scope
        See Also:
        Constant Field Values
      • SCOPE_GMAIL_ALL

        public static final java.lang.String SCOPE_GMAIL_ALL
        Gmail scope
        See Also:
        Constant Field Values
      • SCOPE_GMAIL_READONLY

        public static final java.lang.String SCOPE_GMAIL_READONLY
        Gmail scope read only
        See Also:
        Constant Field Values
      • SCOPE_GMAIL_COMPOSE

        public static final java.lang.String SCOPE_GMAIL_COMPOSE
        Gmail compose scope
        See Also:
        Constant Field Values
      • SCOPE_GMAIL_INSERT

        public static final java.lang.String SCOPE_GMAIL_INSERT
        Gmail insert scope
        See Also:
        Constant Field Values
      • SCOPE_GMAIL_LABELS

        public static final java.lang.String SCOPE_GMAIL_LABELS
        Gmail labels scope
        See Also:
        Constant Field Values
      • SCOPE_GMAIL_METADATA

        public static final java.lang.String SCOPE_GMAIL_METADATA
        Gmail metadata scope
        See Also:
        Constant Field Values
      • SCOPE_GMAIL_MODIFY

        public static final java.lang.String SCOPE_GMAIL_MODIFY
        Gmail modify scope
        See Also:
        Constant Field Values
      • SCOPE_GMAIL_SEND

        public static final java.lang.String SCOPE_GMAIL_SEND
        Gmail send scope
        See Also:
        Constant Field Values
      • SCOPE_CALENDAR

        public static final java.lang.String SCOPE_CALENDAR
        Calendar scope
        See Also:
        Constant Field Values
      • SCOPE_CALENDAR_READONLY

        public static final java.lang.String SCOPE_CALENDAR_READONLY
        Calendar scope read only
        See Also:
        Constant Field Values
      • SCOPE_DRIVE

        public static final java.lang.String SCOPE_DRIVE
        Drive scope
        See Also:
        Constant Field Values
      • SCOPE_DRIVE_FILE

        public static final java.lang.String SCOPE_DRIVE_FILE
        Drive scope file
        See Also:
        Constant Field Values
      • SCOPE_DRIVE_APPDATA

        public static final java.lang.String SCOPE_DRIVE_APPDATA
        Drive scope appdata
        See Also:
        Constant Field Values
      • SCOPE_DRIVE_READONLY

        public static final java.lang.String SCOPE_DRIVE_READONLY
        Drive scope
        See Also:
        Constant Field Values
      • SCOPE_DRIVE_METADATA

        public static final java.lang.String SCOPE_DRIVE_METADATA
        Drive scope
        See Also:
        Constant Field Values
      • SCOPE_DRIVE_METADATA_READONLY

        public static final java.lang.String SCOPE_DRIVE_METADATA_READONLY
        Drive scope
        See Also:
        Constant Field Values
      • SCOPE_SHEETS

        public static final java.lang.String SCOPE_SHEETS
        Sheets scope
        See Also:
        Constant Field Values
      • SCOPE_SHEETS_READONLY

        public static final java.lang.String SCOPE_SHEETS_READONLY
        Sheets scope
        See Also:
        Constant Field Values
      • SCOPE_YOUTUBE

        public static final java.lang.String SCOPE_YOUTUBE
        Youtube account scope
        See Also:
        Constant Field Values
      • SCOPE_YOUTUBE_READONLY

        public static final java.lang.String SCOPE_YOUTUBE_READONLY
        Youtube account scope
        See Also:
        Constant Field Values
      • SCOPE_YOUTUBE_UPLOAD

        public static final java.lang.String SCOPE_YOUTUBE_UPLOAD
        Youtube videos scope
        See Also:
        Constant Field Values
      • DRIVE_REFERENCE_URL

        public static final java.lang.String DRIVE_REFERENCE_URL
        Drive reference URL
        See Also:
        Constant Field Values
    • Method Detail

      • getAPIKey

        public static java.lang.String getAPIKey​(Grant g)
        Get API key
        Parameters:
        g - Grant
      • getLoginURL

        public static java.lang.String getLoginURL​(java.lang.String client_id,
                                                   java.lang.String redirect_uri,
                                                   java.lang.String login_hint,
                                                   java.lang.String scopes,
                                                   java.lang.String state)
        Get the URL of Google OAuth2 login page
        Parameters:
        client_id - Client ID
        redirect_uri - Redirect URI
        login_hint - Optional login hint
        scopes - Optional scopes, see SCOPE_* constants with space as separator (SCOPE_PROFILE, SCOPE_EMAIL and SCOPE_OPENID scopes are set by default)
        state - Unique state
      • getToken

        public static org.json.JSONObject getToken​(java.lang.String client_id,
                                                   java.lang.String client_secret,
                                                   java.lang.String redirect_uri,
                                                   java.lang.String code)
        Get token
        Parameters:
        client_id - Client ID
        client_secret - Client secret
        redirect_uri - Redirect URI
        code - Authorization code
      • getUserData

        public static org.json.JSONObject getUserData​(java.lang.String token)
        Get user data
        Parameters:
        token - Access token
      • refreshToken

        public static org.json.JSONObject refreshToken​(java.lang.String clientId,
                                                       java.lang.String clientSecret,
                                                       java.lang.String refreshToken)
        Refresh token
        Parameters:
        clientId - Client ID
        clientSecret - Client secret
        refreshToken - Refresh token
      • revokeToken

        public static boolean revokeToken​(java.lang.String token)
        Revoke a Google OAuth2 token
        Parameters:
        token - Access token
      • authorize

        public static com.google.api.client.auth.oauth2.Credential authorize​(java.lang.String userId,
                                                                             java.lang.String json,
                                                                             java.util.Collection<java.lang.String> scopes)
                                                                      throws java.io.IOException
        EXPERIMENTAL Authorizes application to access user's protected data.
        Parameters:
        json - Client secret properties (https://developers.google.com/api-client-library/python/guide/aaa_client_secrets)
        Throws:
        java.io.IOException
      • getFontName

        @Deprecated(forRemoval=true,
                    since="4.0")
        public static java.lang.String getFontName​(Grant g)
        Deprecated, for removal: This API element is subject to removal in a future version.
        Use HTMLTool.getGoogleFontName
      • getFontURL

        @Deprecated(forRemoval=true,
                    since="4.0")
        public static java.lang.String getFontURL​(java.lang.String font)
        Deprecated, for removal: This API element is subject to removal in a future version.
        Use HTMLTool.getGoogleFontURL
      • getFontCSS

        @Deprecated(forRemoval=true,
                    since="4.0")
        public static java.lang.String getFontCSS​(java.lang.String font)
        Deprecated, for removal: This API element is subject to removal in a future version.
        Use HTMLTool.getGoogleFontCSS
      • translate

        public static java.lang.String[] translate​(Grant g,
                                                   java.lang.String text,
                                                   java.lang.String source,
                                                   java.lang.String target)
                                            throws java.lang.Exception
        Translate text to specified language
        Parameters:
        g - Grant
        text - Text to translate
        source - Source language
        target - Target language
        Returns:
        Translated text
        Throws:
        java.lang.Exception
      • getToken

        public static java.lang.String getToken​(Grant g)
                                         throws java.io.IOException
        Get token (and refresh it if needed)
        Parameters:
        g - Grant
        Throws:
        java.io.IOException
      • getCredential

        public static com.google.api.client.auth.oauth2.Credential getCredential​(Grant g)
                                                                          throws java.io.IOException
        Get Google credential object from access token
        Parameters:
        g - Grant
        Throws:
        java.io.IOException
      • getCredential

        public static com.google.api.client.auth.oauth2.Credential getCredential​(java.lang.String accessToken)
        Get Google credential object from access token
        Parameters:
        accessToken - Access token
      • getCredentialAccount

        public static com.google.api.client.auth.oauth2.Credential getCredentialAccount​(java.lang.String key)
        Get Google credential from service account
        Parameters:
        key - JSON key
      • getPlusService

        @Deprecated(forRemoval=true,
                    since="5")
        public static com.google.api.services.plus.Plus getPlusService​(com.google.api.client.auth.oauth2.Credential credential)
        Deprecated, for removal: This API element is subject to removal in a future version.
        Get Google+ service
        Parameters:
        credential - Credential
      • getPlusService

        @Deprecated(forRemoval=true,
                    since="5")
        public static com.google.api.services.plus.Plus getPlusService​(Grant g)
                                                                throws java.io.IOException
        Deprecated, for removal: This API element is subject to removal in a future version.
        Get Google+ service
        Parameters:
        g - Grant
        Throws:
        java.io.IOException
      • getPlusService

        @Deprecated(forRemoval=true,
                    since="5")
        public static com.google.api.services.plus.Plus getPlusService​(java.lang.String json)
                                                                throws java.io.IOException
        Deprecated, for removal: This API element is subject to removal in a future version.
        Get Google+ service
        Parameters:
        json - account JSON key
        Throws:
        java.io.IOException
      • plusGetPerson

        @Deprecated(forRemoval=true,
                    since="5")
        public static com.google.api.services.plus.model.Person plusGetPerson​(com.google.api.services.plus.Plus plus,
                                                                              java.lang.String userId)
                                                                       throws java.io.IOException
        Deprecated, for removal: This API element is subject to removal in a future version.
        Get Google+ person
        Parameters:
        plus - Google+ service
        userId - User ID
        Throws:
        java.io.IOException
      • plusGetMe

        @Deprecated(forRemoval=true,
                    since="5")
        public static com.google.api.services.plus.model.Person plusGetMe​(com.google.api.services.plus.Plus plus)
                                                                   throws java.io.IOException
        Deprecated, for removal: This API element is subject to removal in a future version.
        Get Google+ "me" person
        Parameters:
        plus - Google+ service
        Throws:
        java.io.IOException
      • plusSearchPersons

        @Deprecated(forRemoval=true,
                    since="5")
        public static java.util.List<com.google.api.services.plus.model.Person> plusSearchPersons​(com.google.api.services.plus.Plus plus,
                                                                                                  java.lang.String query,
                                                                                                  long maxResults)
                                                                                           throws java.io.IOException
        Deprecated, for removal: This API element is subject to removal in a future version.
        Search Google+ persons
        Parameters:
        plus - Google+ service
        query - Full text query
        maxResults - Max results
        Throws:
        java.io.IOException
      • plusGetActivity

        @Deprecated(forRemoval=true,
                    since="5")
        public static com.google.api.services.plus.model.Activity plusGetActivity​(com.google.api.services.plus.Plus plus,
                                                                                  java.lang.String activityId)
                                                                           throws java.io.IOException
        Deprecated, for removal: This API element is subject to removal in a future version.
        Get Google+ activity
        Parameters:
        plus - Google+ service
        activityId - Activity ID
        Throws:
        java.io.IOException
      • plusGetPublicActivities

        @Deprecated(forRemoval=true,
                    since="5")
        public static java.util.List<com.google.api.services.plus.model.Activity> plusGetPublicActivities​(com.google.api.services.plus.Plus plus,
                                                                                                          java.lang.String userId)
                                                                                                   throws java.io.IOException
        Deprecated, for removal: This API element is subject to removal in a future version.
        Get Google+ public activities
        Parameters:
        plus - Google+ service
        userId - User ID
        Throws:
        java.io.IOException
      • plusSearchActivities

        @Deprecated(forRemoval=true,
                    since="5")
        public static java.util.List<com.google.api.services.plus.model.Activity> plusSearchActivities​(com.google.api.services.plus.Plus plus,
                                                                                                       java.lang.String query,
                                                                                                       long maxResults)
                                                                                                throws java.io.IOException
        Deprecated, for removal: This API element is subject to removal in a future version.
        Search Google+ activities
        Parameters:
        plus - Google+ service
        query - Full text query
        maxResults - Max results
        Throws:
        java.io.IOException
      • getTranslateService

        public static com.google.api.services.translate.Translate getTranslateService​(java.lang.String apiKey)
        Get Translate service
        Parameters:
        apiKey - API key (null means use configured GOOGLE_API_KEY system parameter value)
      • getTranslateService

        public static com.google.api.services.translate.Translate getTranslateService​(Grant g)
        Get Translate service
        Parameters:
        g - Grant
      • translate

        public static java.lang.String translate​(com.google.api.services.translate.Translate service,
                                                 java.lang.String text,
                                                 java.lang.String source,
                                                 java.lang.String target)
                                          throws java.io.IOException
        Traslate
        Parameters:
        service - Translate service
        text - Text to translate
        source - Source language
        target - Target language
        Returns:
        Translated text
        Throws:
        java.io.IOException - If translate service is unavailable
      • getCalendarService

        public static com.google.api.services.calendar.Calendar getCalendarService​(com.google.api.client.auth.oauth2.Credential credential)
        Get Calendar service
        Parameters:
        credential - Credential
      • getCalendarService

        public static com.google.api.services.calendar.Calendar getCalendarService​(Grant g)
                                                                            throws java.io.IOException
        Get Calendar service
        Parameters:
        g - Grant
        Throws:
        java.io.IOException
      • getCalendarService

        public static com.google.api.services.calendar.Calendar getCalendarService​(java.lang.String json)
                                                                            throws java.io.IOException
        Get Calendar service
        Parameters:
        json - acocunt JSON key
        Throws:
        java.io.IOException
      • getGmailService

        public static com.google.api.services.gmail.Gmail getGmailService​(com.google.api.client.auth.oauth2.Credential credential)
        Get Gmail service
        Parameters:
        credential - Credential
      • getGmailService

        public static com.google.api.services.gmail.Gmail getGmailService​(Grant g)
                                                                   throws java.lang.Exception
        Get Gmail service
        Parameters:
        g - Grant
        Throws:
        java.lang.Exception
      • getGmailService

        public static com.google.api.services.gmail.Gmail getGmailService​(java.lang.String json)
                                                                   throws java.lang.Exception
        Get Gmail service
        Parameters:
        json - account JSON key
        Throws:
        java.lang.Exception
      • getDriveService

        public static com.google.api.services.drive.Drive getDriveService​(com.google.api.client.auth.oauth2.Credential credential)
        Get Drive service for the platform name
        Parameters:
        credential - Credential
      • getDriveService

        public static com.google.api.services.drive.Drive getDriveService​(com.google.api.client.auth.oauth2.Credential credential,
                                                                          java.lang.String appName)
        Get Drive service
        Parameters:
        credential - Credential
        appName - Optional Google application name (default is the platform name)
      • getDriveService

        public static com.google.api.services.drive.Drive getDriveService​(Grant g)
                                                                   throws java.io.IOException
        Get Drive service
        Parameters:
        g - Grant
        Throws:
        java.io.IOException
      • getDriveService

        public static com.google.api.services.drive.Drive getDriveService​(java.lang.String json)
                                                                   throws java.io.IOException
        Get Drive service
        Parameters:
        json - account JSON key
        Throws:
        java.io.IOException
      • getDriveFileURL

        public static java.lang.String getDriveFileURL​(java.lang.String fileId)
        URL to open file in drive
      • getDriveFolderURL

        public static java.lang.String getDriveFolderURL​(java.lang.String folderId)
        URL to open folder in drive
      • driveQueryString

        public static java.lang.String driveQueryString​(java.lang.String value)
        Prepare a string for a drive query. Surround the value with single quotes ' and escape single quotes in queries with \', e.g. 'Valentine\'s Day'.
        Parameters:
        value - Value
      • driveAbout

        public static com.google.api.services.drive.model.About driveAbout​(com.google.api.services.drive.Drive drive,
                                                                           java.lang.String fields)
                                                                    throws java.io.IOException
        Get drive about for specified fields
        Parameters:
        drive - Drive service
        fields - Fields (e.g. "user, storageQuota", if null defaults to "storageQuota")
        Throws:
        java.io.IOException
      • driveStorageQuota

        public static com.google.api.services.drive.model.About.StorageQuota driveStorageQuota​(com.google.api.services.drive.Drive drive)
                                                                                        throws java.io.IOException
        Get drive storage quota
        Parameters:
        drive - Drive service
        Throws:
        java.io.IOException
      • driveList

        public static java.util.List<com.google.api.services.drive.model.File> driveList​(com.google.api.services.drive.Drive drive,
                                                                                         java.lang.String query)
                                                                                  throws java.io.IOException
        List drive files from query
        Parameters:
        drive - Drive service
        query - Query string (see https://developers.google.com/drive/api/v3/search-parameters)
        Throws:
        java.io.IOException
      • driveList

        public static java.util.List<com.google.api.services.drive.model.File> driveList​(com.google.api.services.drive.Drive drive,
                                                                                         java.lang.String query,
                                                                                         java.lang.String fields)
                                                                                  throws java.io.IOException
        List drive files from query
        Parameters:
        drive - Drive service
        query - Query string (see https://developers.google.com/drive/api/v3/search-parameters)
        fields - Fields (e.g. "files/id, files/name", if null all fields)
        Throws:
        java.io.IOException
      • driveListFolder

        public static java.util.List<com.google.api.services.drive.model.File> driveListFolder​(com.google.api.services.drive.Drive drive,
                                                                                               java.lang.String query,
                                                                                               java.lang.String folderId)
                                                                                        throws java.io.IOException
        List drive files in a folder
        Parameters:
        drive - Drive service
        query - Query string (see https://developers.google.com/drive/api/v3/search-parameters)
        folderId - Optional parent folder Id (or 'root' or null=anywhere)
        Throws:
        java.io.IOException
      • driveListFolder

        public static java.util.List<com.google.api.services.drive.model.File> driveListFolder​(com.google.api.services.drive.Drive drive,
                                                                                               java.lang.String query,
                                                                                               java.lang.String folderId,
                                                                                               java.lang.String fields,
                                                                                               boolean trashed)
                                                                                        throws java.io.IOException
        List drive files in a folder
        Parameters:
        drive - Drive service
        query - Query string (see https://developers.google.com/drive/api/v3/search-parameters)
        folderId - Optional parent folder Id (or 'root' or null=anywhere)
        fields - Fields (e.g. "files/id, files/name", if null all fields)
        trashed - true to search in trash
        Throws:
        java.io.IOException
      • driveGet

        public static com.google.api.services.drive.model.File driveGet​(com.google.api.services.drive.Drive drive,
                                                                        java.lang.String fileId,
                                                                        java.lang.String fields)
                                                                 throws java.io.IOException
        Get drive file
        Parameters:
        drive - Drive service
        fileId - File ID
        fields - Fields (e.g. "files/id, files/name", if null all fields)
        Throws:
        java.io.IOException
      • driveCreate

        public static com.google.api.services.drive.model.File driveCreate​(com.google.api.services.drive.Drive drive,
                                                                           java.lang.String name,
                                                                           java.lang.String mime,
                                                                           java.io.InputStream in)
                                                                    throws java.io.IOException
        Create drive file (override)
        Parameters:
        drive - Drive service
        name - File name
        mime - File MIME type
        in - Data input stream
        Throws:
        java.io.IOException
      • driveCreate

        public static com.google.api.services.drive.model.File driveCreate​(com.google.api.services.drive.Drive drive,
                                                                           java.lang.String name,
                                                                           java.lang.String mime,
                                                                           byte[] data)
                                                                    throws java.io.IOException
        Create drive file (override)
        Parameters:
        drive - Drive service
        name - File name
        mime - File MIME type
        data - Data
        Throws:
        java.io.IOException
      • driveCreate

        public static com.google.api.services.drive.model.File driveCreate​(com.google.api.services.drive.Drive drive,
                                                                           java.lang.String name,
                                                                           java.lang.String mime,
                                                                           byte[] data,
                                                                           java.lang.String folderId,
                                                                           boolean override)
                                                                    throws java.io.IOException
        Create drive file
        Parameters:
        drive - Drive service
        name - File name
        mime - File MIME type
        data - Data
        folderId - Optional parent folder Id
        override - true to replace existing file (false will create a second file with the same name and new Id)
        Throws:
        java.io.IOException
      • driveCreate

        public static com.google.api.services.drive.model.File driveCreate​(com.google.api.services.drive.Drive drive,
                                                                           java.lang.String name,
                                                                           java.lang.String mime,
                                                                           java.io.InputStream in,
                                                                           java.lang.String folderId,
                                                                           boolean override)
                                                                    throws java.io.IOException
        Create drive file
        Parameters:
        drive - Drive service
        name - File name
        mime - File MIME type
        in - Data input stream
        folderId - Optional parent folder Id
        override - true to replace existing file
        Throws:
        java.io.IOException
      • driveUpdate

        public static com.google.api.services.drive.model.File driveUpdate​(com.google.api.services.drive.Drive drive,
                                                                           java.lang.String fileId,
                                                                           java.lang.String name,
                                                                           java.lang.String mime,
                                                                           byte[] data)
                                                                    throws java.io.IOException
        Update a file in drive
        Parameters:
        drive - Drive service
        fileId - File Id to update
        name - New name
        mime - Optional mime type
        data - File data
        Throws:
        java.io.IOException
      • driveUpdate

        public static com.google.api.services.drive.model.File driveUpdate​(com.google.api.services.drive.Drive drive,
                                                                           java.lang.String fileId,
                                                                           java.lang.String name,
                                                                           java.lang.String mime,
                                                                           java.io.InputStream in)
                                                                    throws java.io.IOException
        Update a file in drive
        Parameters:
        drive - Drive service
        fileId - File Id to update
        name - New name
        mime - Optional mime type
        in - Data inpout stream
        Throws:
        java.io.IOException
      • driveDelete

        public static void driveDelete​(com.google.api.services.drive.Drive drive,
                                       java.lang.String fileId)
                                throws java.io.IOException
        Delete drive file
        Parameters:
        drive - Drive service
        fileId - File ID
        Throws:
        java.io.IOException
      • driveMove

        public static com.google.api.services.drive.model.File driveMove​(com.google.api.services.drive.Drive drive,
                                                                         java.lang.String fileId,
                                                                         java.lang.String folderId)
                                                                  throws java.io.IOException
        Move a file to folder
        Parameters:
        drive - Drive service
        fileId - File ID
        folderId - Folder Id
        Throws:
        java.io.IOException
      • driveCreateFolder

        public static com.google.api.services.drive.model.File driveCreateFolder​(com.google.api.services.drive.Drive drive,
                                                                                 java.lang.String name,
                                                                                 java.lang.String parentId,
                                                                                 boolean unique)
                                                                          throws java.io.IOException
        Create a drive folder
        Parameters:
        drive - Drive service
        name - Folder name
        parentId - Optional parent folder Id (default = root)
        unique - True do get the same folder if already exists
        Throws:
        java.io.IOException
      • driveListPermissions

        public static java.util.List<com.google.api.services.drive.model.Permission> driveListPermissions​(com.google.api.services.drive.Drive drive,
                                                                                                          java.lang.String fileId)
                                                                                                   throws java.io.IOException
        List all permissions on file
        Parameters:
        drive - Drive service
        fileId - File or folder Id
        Returns:
        Permissions list
        Throws:
        java.io.IOException
      • driveCreatePermissionUser

        public static com.google.api.services.drive.model.Permission driveCreatePermissionUser​(com.google.api.services.drive.Drive drive,
                                                                                               java.lang.String fileId,
                                                                                               java.lang.String email,
                                                                                               boolean canWrite)
                                                                                        throws java.io.IOException
        Add file permission to user
        Parameters:
        drive - Drive service
        fileId - File or folder Id
        email - user email
        canWrite - false for read only
        Throws:
        java.io.IOException
      • driveCreatePermissionUser

        public static com.google.api.services.drive.model.Permission driveCreatePermissionUser​(com.google.api.services.drive.Drive drive,
                                                                                               java.lang.String fileId,
                                                                                               java.lang.String email,
                                                                                               boolean canWrite,
                                                                                               boolean notif)
                                                                                        throws java.io.IOException
        Add file permission to user
        Parameters:
        drive - Drive service
        fileId - File or folder Id
        email - user email
        canWrite - false for read only
        notif - Send email notifications?
        Throws:
        java.io.IOException
      • driveCreatePermissionGroup

        public static com.google.api.services.drive.model.Permission driveCreatePermissionGroup​(com.google.api.services.drive.Drive drive,
                                                                                                java.lang.String fileId,
                                                                                                java.lang.String email,
                                                                                                boolean canWrite)
                                                                                         throws java.io.IOException
        Add file permission to group (same as user)
        Parameters:
        drive - Drive service
        fileId - File or folder Id
        email - group email
        canWrite - false for read only
        Throws:
        java.io.IOException
      • driveCreatePermissionGroup

        public static com.google.api.services.drive.model.Permission driveCreatePermissionGroup​(com.google.api.services.drive.Drive drive,
                                                                                                java.lang.String fileId,
                                                                                                java.lang.String email,
                                                                                                boolean canWrite,
                                                                                                boolean notif)
                                                                                         throws java.io.IOException
        Add file permission to group (same as user)
        Parameters:
        drive - Drive service
        fileId - File or folder Id
        email - group email
        canWrite - false for read only
        notif - Send email notifications?
        Throws:
        java.io.IOException
      • driveCreatePermissionDomain

        public static com.google.api.services.drive.model.Permission driveCreatePermissionDomain​(com.google.api.services.drive.Drive drive,
                                                                                                 java.lang.String fileId,
                                                                                                 java.lang.String domain,
                                                                                                 boolean canWrite)
                                                                                          throws java.io.IOException
        Add file permission to domain
        Parameters:
        drive - Drive service
        fileId - File or folder Id
        domain - Domain to grant ex mydomain.com
        canWrite - false for read only
        Throws:
        java.io.IOException
      • driveCreatePermissionDomain

        public static com.google.api.services.drive.model.Permission driveCreatePermissionDomain​(com.google.api.services.drive.Drive drive,
                                                                                                 java.lang.String fileId,
                                                                                                 java.lang.String domain,
                                                                                                 boolean canWrite,
                                                                                                 boolean notif)
                                                                                          throws java.io.IOException
        Add file permission to domain
        Parameters:
        drive - Drive service
        fileId - File or folder Id
        domain - Domain to grant ex mydomain.com
        canWrite - false for read only
        notif - Send email notifications?
        Throws:
        java.io.IOException
      • driveCreatePermissionAnyone

        public static com.google.api.services.drive.model.Permission driveCreatePermissionAnyone​(com.google.api.services.drive.Drive drive,
                                                                                                 java.lang.String fileId,
                                                                                                 boolean canWrite)
                                                                                          throws java.io.IOException
        Add file permission to anyone
        Parameters:
        drive - Drive service
        fileId - File or folder Id
        canWrite - false for read only
        Throws:
        java.io.IOException
      • driveCreatePermissionAnyone

        public static com.google.api.services.drive.model.Permission driveCreatePermissionAnyone​(com.google.api.services.drive.Drive drive,
                                                                                                 java.lang.String fileId,
                                                                                                 boolean canWrite,
                                                                                                 boolean notif)
                                                                                          throws java.io.IOException
        Add file permission to anyone
        Parameters:
        drive - Drive service
        fileId - File or folder Id
        canWrite - false for read only
        notif - Send email notifications?
        Throws:
        java.io.IOException
      • driveDeletePermission

        public static void driveDeletePermission​(com.google.api.services.drive.Drive drive,
                                                 java.lang.String fileId,
                                                 java.lang.String permissionId)
                                          throws java.io.IOException
        Remove file permission
        Parameters:
        drive - Drive service
        fileId - File or folder Id
        permissionId - Permission Id
        Throws:
        java.io.IOException
      • getSheetsService

        public static com.google.api.services.sheets.v4.Sheets getSheetsService​(com.google.api.client.auth.oauth2.Credential credential)
        Get Sheets service
        Parameters:
        credential - Credential
      • getSheetsService

        public static com.google.api.services.sheets.v4.Sheets getSheetsService​(Grant g)
                                                                         throws java.lang.Exception
        Get Sheets service
        Parameters:
        g - Grant
        Throws:
        java.lang.Exception
      • getSheetsService

        public static com.google.api.services.sheets.v4.Sheets getSheetsService​(java.lang.String json)
                                                                         throws java.lang.Exception
        Get Sheets service
        Parameters:
        json - account JSON key
        Throws:
        java.lang.Exception
      • getYouTubeService

        public static com.google.api.services.youtube.YouTube getYouTubeService​(com.google.api.client.auth.oauth2.Credential credential)
        Get YouTube service
        Parameters:
        credential - Credential
      • getYouTubeService

        public static com.google.api.services.youtube.YouTube getYouTubeService​(Grant g)
                                                                         throws java.io.IOException
        Get YouTube service
        Parameters:
        g - Grant
        Throws:
        java.io.IOException
      • getYouTubeService

        public static com.google.api.services.youtube.YouTube getYouTubeService​(java.lang.String json)
                                                                         throws java.io.IOException
        Get YouTube service
        Parameters:
        json - account JSON key
        Throws:
        java.io.IOException