Google ドライブ #ファイル権限: AnyoneWithLink を追加

Google ドライブ: ファイル権限, AnyoneWithLink を追加
Google ドライブ: ファイル権限, AnyoneWithLink を追加 (Google Drive: File Permissions, Add AnyoneWithLink)
ファイルに AnyoneWithLink(リンクを知っている全員に対する閲覧権限)を作成します。閲覧者(リンクを知らされた人)は Google アカウントへのサインインを要しません。
Configs
  • A: 通信許可設定(OAuth2)を選択してください *
  • B: ファイルID(fileId)をセットしてください *#{EL}
Script (click to open)
// GraalJS Script (engine type: 2)
/*
Notes(en):
- 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.
- No error will occur even if you execute it while it has already been created.
Notes(ja):
- ファイル権限を持つユーザにより、OAuth認可される必要があります。(以下のうち少なくとも1つ)
    - https://www.googleapis.com/auth/drive
    - https://www.googleapis.com/auth/drive.file
- マイドライブと共有ドライブの両方をサポートします。共有アイテムも参照可能です。
- すでに追加済みの状態で実行してもエラーにはなりません。
Notes:
- To Get "ClientId" and "Secret"
    - Access to https://console.developers.google.com/
- 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."
        - } }

*/

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

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


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


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

// prepare request1
// ref) https://developers.google.com
//            /drive/api/v3/reference/permissions/create
let request1Obj = {};
    request1Obj.role = "reader";
    request1Obj.type = "anyone";
let uri1     = "https://www.googleapis.com/drive/v3/files/" +
                strFileId + "/permissions";
const token  = httpClient.getOAuth2Token( strOauthSetting );
let request1 = httpClient.begin(); // HttpRequestWrapper
    request1 = request1.bearer( token );
    request1 = request1.queryParam( "supportsAllDrives", "true" );
    request1 = request1.body( JSON.stringify( request1Obj ), "application/json" );
engine.log( " AutomatedTask ApiRequest Prepared" );

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

// parse response1
// (nothing)
/* engine.log( response1Body ); // debug
response sample
{
 "kind": "drive#permission",
 "id": "anyoneWithLink",
 "type": "anyone",
 "role": "reader",
 "allowFileDiscovery": false
}
*/


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

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

Download

2020-10-05 (C) Questetra, Inc. (MIT License)
https://support.questetra.com/ja/addons/google-drive-file-permissions-add-anyonewithlink/
Addonファイルのインポートは Professional でのみご利用いただけます

Notes

Capture

ファイルに AnyoneWithLink(リンクを知っている全員に対する閲覧権限)を作成します。閲覧者(リンクを知らされた人)は Google アカウントへのサインインを要しません。

See also

コメントを残す

このサイトはスパムを低減するために Akismet を使っています。コメントデータの処理方法の詳細はこちらをご覧ください

Questetra Supportをもっと見る

今すぐ購読し、続きを読んで、すべてのアーカイブにアクセスしましょう。

続きを読む

上部へスクロール