Google Drive: File Permissions, Remove Reader
Google Drive: File Permissions, Remove Reader
Deletes a Reader permission. The permissionId is required.
Configs
  • A: Select Authorization Setting (OAuth2) *
  • B: Set File ID (fileId) *#{EL}
  • C: Set Permission ID to be deleted *#{EL}
Script (click to open)
// GraalJS Script (engine type: 2)
/*
- This request requires authorization with at least one of the following scopes:
    - https://www.googleapis.com/auth/drive
    - https://www.googleapis.com/auth/drive.file (only files created by the app)
- Supports both My Drives and shared drives. Shared-with-me are also referable.
- 404 error will occur even if executed while it has already been deleted.
- ファイル権限を持つユーザにより、OAuth認可される必要があります。(以下のうち少なくとも1つ)
    - https://www.googleapis.com/auth/drive
    - https://www.googleapis.com/auth/drive.file
- マイドライブと共有ドライブの両方をサポートします。共有アイテムも参照可能です。
- すでに削除済みの状態で実行すると404エラーになります。
- "FileID" in URL
    - https://docs.google.com/spreadsheets/d/FILEID/edit#gid=0
    - https://docs.google.com/document/d/FILEID/edit
    - https://drive.google.com/file/d/FILEID/view
- To Get "ClientId" and "Secret"
    - Access to https://console.developers.google.com/apis/credentials
- OAuth Setting sample
    - "Authorization Endpoint URL"
        - https://accounts.google.com/o/oauth2/auth?access_type=offline&approval_prompt=force
    - "Token Endpoint URL"
        - https://accounts.google.com/o/oauth2/token
    - "Scope"
        - https://www.googleapis.com/auth/drive.file
- Error Log sample (wrong fileId or Scope)
    - AutomatedTask UnexpectedResponseError: 404
        - { "error": {
        - "errors": [ {
            - "domain": "global",
            - "reason": "notFound",
            - "message": "File not found: 1lKhxxxxcQ2Fxxxx1d0lxxxxCftexxxxQ.",
            - "locationType": "parameter",
            - "location": "fileId"
        - } ],
        - "code": 404,
        - "message": "File not found: 1lKhxxxxcQ2Fxxxx1d0lxxxxCftexxxxQ."
        - } }
    - AutomatedTask UnexpectedResponseError: 404
        - { "error": {
        - "errors": [ {
            - "domain": "global",
            - "reason": "notFound",
            - "message": "Permission not found: 13309999178899996487.",
            - "locationType": "parameter",
            - "location": "permissionId"
            - } ],
        - "code": 404,
        - "message": "Permission not found: 13309999178899996487."
        - } }

*/

//////// START "main()" /////////////////////////////////////////////////////////////////
main();
function main(){ 

//// == Config Retrieving / 工程コンフィグの参照 ==
const strOauthSetting       = configs.get( "OAuth2ConfA" );   // required
const strFileId             = configs.get( "StrConfB" ) + ""; // required
const strPermissionId       = configs.get( "StrConfC" ) + ""; // required

if( strFileId === "" ){
  throw new Error( "\n AutomatedTask ConfigError:" +
                   " Config {FileId B} not specified \n" );
}
if( strPermissionId === "" ){
  throw new Error( "\n AutomatedTask ConfigError:" +
                   " Config {PermissionId C} not specified \n" );
}


//// == Data Retrieving / ワークフローデータの参照 ==
// (nothing)


//// == Calculating / 演算 ==

// prepare request1
// ref) https://developers.google.com
//            /drive/api/v3/reference/permissions/delete
let uri1     = "https://www.googleapis.com/drive/v3/files/" +
                strFileId + "/permissions/" + strPermissionId;
const token  = httpClient.getOAuth2Token( strOauthSetting );
let request1 = httpClient.begin(); // HttpRequestWrapper
    request1 = request1.bearer( token );
    request1 = request1.queryParam( "supportsAllDrives", "true" );
engine.log( " AutomatedTask ApiRequest Prepared" );

// delete request1
const response1     = request1.delete( uri1 );       // HttpResponseWrapper
engine.log( " AutomatedTask ApiRequest Start: " + uri1 );
const response1Code = response1.getStatusCode() + ""; // (primitive string)
const response1Body = response1.getResponseAsString() + "";
if( response1Code !== "204"){
  throw new Error( "\n AutomatedTask UnexpectedResponseError: " +
                    response1Code + "\n" + response1Body + "\n" );
}
engine.log( " AutomatedTask ApiResponse Status: " + response1Code );

// parse response1
/* engine.log( response1Body ); // debug
// (nothing)
*/


//// == Data Updating / ワークフローデータへの代入 ==
// (nothing)


} //////// END "main()" /////////////////////////////////////////////////////////////////

Download

2020-10-07 (C) Questetra, Inc. (MIT License)
https://support.questetra.com/addons/google-drive-file-permissions-remove-reader/
The Addon-import feature is available with Professional edition.

Notes

Capture

Deletes a Reader permission. The permissionId is required.

See also

1 thought on “Google Drive #File_Permissions: Remove Reader”

  1. Pingback: Google Drive: File Permissions, Add Reader – Questetra Support

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: