1
1

More than 3 years have passed since last update.

Node.jsでGoogle Slides内のテキストの書き換え

Last updated at Posted at 2020-02-09

Google Slides APIをNode.jsから触ってみてます。

の記事の続きです。

batchUpdate()で更新

presentations.batchUpdateでどうやら更新ができそうです。

presentations.batchUpdate()の

presentations.batchUpdate()の使い方がいまいち分からなかったけど、stackoverflowの投稿を参考に

presentationId: プレゼンテーションIDを指定, 
resource: {
   requests: {
      //ここにリクエストする内容を入れる
   }
}

みたいな使い方というのが分かりました。

app.js
省略

function listSlides(auth) {
  const slides = google.slides({version: 'v1', auth});

  slides.presentations.batchUpdate({
    presentationId: presentationId,
    resource: {
      requests: {
        replaceAllText: {
          containsText: {
            text: "Node.js" //置き換え前のテキスト
          },
          replaceText: "Hoge" //置き換え後のテキスト
        }
      }
    }
  }, (err, res) => {
      if (err) return console.log('The API returned an error: ' + err);
      console.log(res.data);
  });
}

Node.jsというテキストをHogeに書き換えます。

実行

こんな感じで書き換えができました。

所感

今回はreplaceAllTextというリクエストをしましたが、他のリクエスト方法もあるので試していきたいです。

/v1/presentations/request

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1