액션 독려

Action 객체를 사용하면 양방향 빌드가 가능합니다. Google Workspace 부가기능에 적용될 예정입니다. 특성은 사용자가 홈 화면의 위젯 (예: 버튼)과 설정할 수 있습니다

작업은 위젯 핸들러 함수 작업을 트리거하는 조건도 정의합니다. 트리거되면 작업은 지정된 콜백 함수입니다. 콜백 함수는 이벤트 객체 클라이언트 측 상호작용에 대한 정보 이때 콜백 함수를 호출하고 특정 응답 객체를 반환하도록 합니다.

예를 들어, 오류가 발생할 때 새 카드를 만들어 표시하는 버튼을 원한다고 가정해 보겠습니다. 있습니다. 이를 위해 새 버튼 위젯을 만들고 버튼 위젯을 핸들러 함수 setOnClickAction(action) 드림 카드 빌딩 Action을 설정합니다. 이 정의한 Action에서 Apps Script를 지정합니다. 버튼을 클릭할 때 실행되는 콜백 함수입니다. 이 경우 콜백 함수를 구현하여 원하는 카드를 빌드하고 ActionResponse 드림 객체를 지정합니다. 응답 객체는 콜백이 카드를 표시하도록 부가기능에 지시합니다. 함수를 빌드하겠습니다.

이 페이지에서는 부가기능

상호작용 유도

Drive를 확장하는 Google Workspace 부가기능에는 다음이 포함됩니다. 추가적인 Drive 관련 위젯 작업이 있습니다. 이 작업을 수행하려면 연결된 콜백 함수 작업 특수 응답 객체를 반환합니다.

시도한 작업 콜백 함수가 반환해야 함
선택한 파일의 파일 액세스 요청 DriveItemsSelectedActionResponse

이러한 위젯 작업 및 응답 객체를 활용하려면 다음을 모두 충족해야 합니다. 가 true여야 합니다.

  • 이 작업은 사용자가 하나 이상의 Drive 항목을 선택한 경우 트리거됩니다.
  • 부가기능에는 https://www.googleapis.com/auth/drive.file Drive 범위는 합니다.

선택한 파일의 파일 액세스 권한 요청

다음 예는 Google 게시자용 컨텍스트 인터페이스를 빌드하는 방법을 보여줍니다. 사용자가 하나 이상의 Drive 항목을 선택할 때 트리거되는 드라이브입니다. 이 예를 들어 각 항목을 테스트하여 부가기능에 액세스 권한이 부여되었는지 확인합니다. 그렇지 않은 경우 DriveItemsSelectedActionResponse를 사용합니다. 객체를 사용하여 사용자에게 해당 권한을 요청합니다. 다음에 대해 권한이 부여되면 항목을 선택하면 부가기능에 해당 항목의 Drive 할당량 사용량이 표시됩니다.

/**
 * Build a simple card that checks selected items' quota usage. Checking
 * quota usage requires user-permissions, so this add-on provides a button
 * to request `drive.file` scope for items the add-on doesn't yet have
 * permission to access.
 *
 * @param e The event object passed containing contextual information about
 *    the Drive items selected.
 * @return {Card}
 */
function onDriveItemsSelected(e) {
  var builder =  CardService.newCardBuilder();

  // For each item the user has selected in Drive, display either its
  // quota information or a button that allows the user to provide
  // permission to access that file to retrieve its quota details.
  e['drive']['selectedItems'].forEach(
    function(item){
      var cardSection = CardService.newCardSection()
          .setHeader(item['title']);

      // This add-on uses the recommended, limited-permission `drive.file`
      // scope to get granular per-file access permissions.
      // See: https://developers.google.com/drive/api/v2/about-auth
      if (item['addonHasFileScopePermission']) {
        // If the add-on has access permission, read and display its
        // quota.
        cardSection.addWidget(
          CardService.newTextParagraph().setText(
              "This file takes up: " + getQuotaBytesUsed(item['id'])));
      } else {
        // If the add-on does not have access permission, add a button
        // that allows the user to provide that permission on a per-file
        // basis.
        cardSection.addWidget(
          CardService.newTextParagraph().setText(
              "The add-on needs permission to access this file's quota."));

        var buttonAction = CardService.newAction()
          .setFunctionName("onRequestFileScopeButtonClicked")
          .setParameters({id: item.id});

        var button = CardService.newTextButton()
          .setText("Request permission")
          .setOnClickAction(buttonAction);

        cardSection.addWidget(button);
      }

      builder.addSection(cardSection);
    });

  return builder.build();
}

/**
 * Callback function for a button action. Instructs Drive to display a
 * permissions dialog to the user, requesting `drive.file` scope for a
 * specific item on behalf of this add-on.
 *
 * @param {Object} e The parameters object that contains the item's
 *   Drive ID.
 * @return {DriveItemsSelectedActionResponse}
 */
function onRequestFileScopeButtonClicked (e) {
  var idToRequest = e.parameters.id;
  return CardService.newDriveItemsSelectedActionResponseBuilder()
      .requestFileScope(idToRequest).build();
}

/**
 * Use the Advanced Drive Service
 * (See https://developers.google.com/apps-script/advanced/drive),
 * with `drive.file` scope permissions to request the quota usage of a
 * specific Drive item.
 *
 * @param {string} itemId The ID of the item to check.
 * @return {string} A description of the item's quota usage, in bytes.
 */
function getQuotaBytesUsed(itemId) {
  try {
    return Drive.Files.get(itemId,{fields: "quotaBytesUsed"})
        .quotaBytesUsed + " bytes";
  } catch (e) {
    return "Error fetching how much quota this item uses. Error: " + e;
  }
}