Class GoogleAPITool


  • public class GoogleAPITool
    extends java.lang.Object
    Google API toolbox
    • Method Summary

      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 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, java.io.InputStream data, 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 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 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 driveCreatePermissionUser​(com.google.api.services.drive.Drive drive, java.lang.String fileId, java.lang.String email, boolean canWrite)
      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 data)
      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.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 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 java.lang.String getFontCSS​(java.lang.String font)
      Get Google font CSS statement
      static java.lang.String getFontName​(Grant g)
      Get Google font URL
      static java.lang.String getFontURL​(java.lang.String font)
      Get Google font URL
      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 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)
      Get Google+ service
      static com.google.api.services.plus.Plus getPlusService​(Grant g)
      Get Google+ service
      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 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.plus.model.Activity plusGetActivity​(com.google.api.services.plus.Plus plus, java.lang.String activityId)
      Get Google+ activity
      static com.google.api.services.plus.model.Person plusGetMe​(com.google.api.services.plus.Plus plus)
      Get Google+ "me" person
      static com.google.api.services.plus.model.Person plusGetPerson​(com.google.api.services.plus.Plus plus, java.lang.String userId)
      Get Google+ person
      static java.util.List<com.google.api.services.plus.model.Activity> plusGetPublicActivities​(com.google.api.services.plus.Plus plus, java.lang.String userId)
      Get Google+ public activities
      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)
      Search Google+ activities
      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)
      Search Google+ persons
      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)  
      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

      • 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
      • 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
        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 (SCOPE_PROFILE, SCOPE_EMAIL and SCOPE_OPENID scopes are set by default) with space as separator
        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.lang.Exception
        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.lang.Exception
      • getFontName

        public static java.lang.String getFontName​(Grant g)
        Get Google font URL
        Parameters:
        g - Grant
        Returns:
        Google font name
      • getFontURL

        public static java.lang.String getFontURL​(java.lang.String font)
        Get Google font URL
        Parameters:
        font - Font name
        Returns:
        Google font URL
      • getFontCSS

        public static java.lang.String getFontCSS​(java.lang.String font)
        Get Google font CSS statement
        Parameters:
        font - Font name
        Returns:
        CSS statement to apply font
      • 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
      • getPlusService

        public static com.google.api.services.plus.Plus getPlusService​(com.google.api.client.auth.oauth2.Credential credential)
        Get Google+ service
        Parameters:
        credential - Credential
      • getPlusService

        public static com.google.api.services.plus.Plus getPlusService​(Grant g)
                                                                throws java.io.IOException
        Get Google+ service
        Parameters:
        g - Grant
        Throws:
        java.io.IOException
      • plusGetPerson

        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
        Get Google+ person
        Parameters:
        plus - Google+ service
        userId - User ID
        Throws:
        java.io.IOException
      • plusGetMe

        public static com.google.api.services.plus.model.Person plusGetMe​(com.google.api.services.plus.Plus plus)
                                                                   throws java.io.IOException
        Get Google+ "me" person
        Parameters:
        plus - Google+ service
        Throws:
        java.io.IOException
      • plusSearchPersons

        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
        Search Google+ persons
        Parameters:
        plus - Google+ service
        query - Full text query
        maxResults - Max results
        Throws:
        java.io.IOException
      • plusGetActivity

        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
        Get Google+ activity
        Parameters:
        plus - Google+ service
        activityId - Activity ID
        Throws:
        java.io.IOException
      • plusGetPublicActivities

        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
        Get Google+ public activities
        Parameters:
        plus - Google+ service
        userId - User ID
        Throws:
        java.io.IOException
      • plusSearchActivities

        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
        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
        Throws:
        java.io.IOException
      • 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
      • 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
      • 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
      • 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 data)
                                                                    throws java.io.IOException
        Create drive file (override)
        Parameters:
        drive - Drive service
        name - File name
        mime - File MIME type
        data - File 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)
                                                                    throws java.io.IOException
        Create drive file (override)
        Parameters:
        drive - Drive service
        name - File name
        mime - File MIME type
        data - File 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 - File 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 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 - File data
        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 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
      • 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
      • 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
      • 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
      • 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
      • 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
      • 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