Google スライド: ページ; 複製 (Google Slides: Page; Duplicate)

指定スライドを複製し、次ページに挿入します。スライドの指定が無い場合は最終スライドが複製されます。

2019-08-27 (C) Questetra, Inc. (MIT License)
https://support.questetra.com/ja/addons/google-slides-page-duplicate/

Configs
  • A: 通信許可の設定名([OAuth2.0設定]メニュー)を選択してください *
  • B: ファイルの PRESENTATION-ID をセットしてください (ファイルURI内の44文字) * #{EL}
  • C: スライドの Object-ID をセットしてください (URI内のid.以降) #{EL}
  • D: 新スライドの Object-ID が格納される文字列型データ項目を選択してください (更新)
Script
// (c) 2019, Questetra, Inc. (the MIT License)

//// == OAuth2 Setting example ==
// 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/presentations https://www.googleapis.com/auth/spreadsheets.readonly"
// Client ID:
//  ( from https://console.developers.google.com/ )
// Consumer Secret:
//  ( from https://console.developers.google.com/ )
//  *Redirect URLs: "https://s.questetra.net/oauth2callback"


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

//// == Config Retrieving / 工程コンフィグの参照 ==
const oauth2   = configs.get( "conf_OAuth2"  ) + "";
const presentationId = configs.get( "conf_PresentationId") + "";
let   objectId = configs.get( "conf_ObjectId") + "";
const dataIdD  = configs.get( "conf_DataIdD" ) + "";
// 'java.lang.String' (String Obj) to javascript primitive 'string'

engine.log( " AutomatedTask Config: Presentation ID: " + presentationId );
if( objectId === "" ){
  engine.log( " AutomatedTask Config: Object ID: not set" );
}else{
  engine.log( " AutomatedTask Config: Object ID: " + objectId );
}


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


//// == Calculating / 演算 ==
/// obtain OAuth2 Access Token
const token   = httpClient.getOAuth2Token( oauth2 );

/// get ID of Last-Slide
if( objectId === "" ){
  let apiRequest = httpClient.begin(); // HttpRequestWrapper
  apiRequest     = apiRequest.bearer( token );
  const apiUri = "https://slides.googleapis.com/v1/presentations/" + presentationId;
  engine.log( " AutomatedTask Trying: GET " + apiUri );
  const response = apiRequest.get( apiUri );
  const responseCode = response.getStatusCode() + "";
  engine.log( " AutomatedTask ApiResponse: Status " + responseCode );
  if( responseCode !== "200"){
    throw new Error( "\n AutomatedTask UnexpectedResponseError: "
           + responseCode + "\n" + response.getResponseAsString() + "\n" );
  }
  const responseStr = response.getResponseAsString() + "";
  const responseObj = JSON.parse( responseStr );
  const SlideNum = responseObj.slides.length;
  objectId = responseObj.slides[SlideNum - 1].objectId;
}

/// post DuplicateObjectRequest
let requestObj2 = {};
    requestObj2.requests = [];
    requestObj2.requests[0] = {};
    requestObj2.requests[0].duplicateObject = {};
    requestObj2.requests[0].duplicateObject.objectId = objectId;
let apiRequest2 = httpClient.begin(); // HttpRequestWrapper
apiRequest2 = apiRequest2.bearer( token );
apiRequest2 = apiRequest2.body( JSON.stringify( requestObj2 ), "application/json" )
const apiUri2 = "https://slides.googleapis.com/v1/presentations/"
                + presentationId + ":batchUpdate";
engine.log( " AutomatedTask Trying: POST " + apiUri2 );
const response2 = apiRequest2.post( apiUri2 );
const responseCode2 = response2.getStatusCode() + "";
engine.log( " AutomatedTask ApiResponse: Status " + responseCode2 );
if( responseCode2 !== "200"){
  throw new Error( "\n AutomatedTask UnexpectedResponseError: "
         + responseCode2 + "\n" + response2.getResponseAsString() + "\n" );
}
const responseStr2 = response2.getResponseAsString() + "";
const responseObj2 = JSON.parse( responseStr2 );
const duplicateObject = responseObj2.replies[0].duplicateObject.objectId;


//// == Data Updating / ワークフローデータへの代入 ==
if( dataIdD !== "" ){
  engine.setDataByNumber( dataIdD, duplicateObject );
}

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

Download

Capture

Notes

  1. Presentation ID: https://docs.google.com/presentation/d/1p33hGJFUNYixBmMeaV81nsOVYGUUrZIFyErinFp3CI8/edit#slide=id.g613777c84a_0_0
  2. Slide Object ID: https://docs.google.com/presentation/d/1p33hGJFUNYixBmMeaV81nsOVYGUUrZIFyErinFp3CI8/edit#slide=id.g613777c84a_0_0

See also

コメントを残す

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

%d人のブロガーが「いいね」をつけました。