2025年5月9日金曜日

Google Formsで動画を追加したい


今回はGoogleフォームに「動画を追加」してみます


フォームの編集画面


YouTube全体を検索またはURLを貼り付けます


今回は特定のURLを貼り付けてみます

検索結果で対象の動画を選択して右下の「挿入」ボタンをクリックします


フォームに動画が追加されます



タイトルや質問を入力してフォームを調整します




フォームの回答画面




Apps Script で作成する場合

以下の Code.gs で formName, description, videoUrl, videoTitle, videoHelpText , questionTitle, choices の値を書き換えて

createFormWithVideoAndQuestion() を実行すると

上記のような「動画を追加」したフォームが作成されます



Code.gs
function createFormWithVideoAndQuestion() {
const formName = 'Google Forms Quiz with Video';
const description = 'Please watch the video and select the correct URL to create a new Google Form.';
const videoUrl = 'https://www.youtube.com/watch?v=-34hDApWjiM';
const videoTitle = 'Watch this video';
const videoHelpText = 'Please watch this video before answering the question.';
const questionTitle = 'What is the URL to create a new Google Form?';
const choices = ['form.new', 'doc.new', 'sheet.new'];

// Create the form
const form = FormApp.create(formName);
form.setDescription(description);

// Add YouTube video
form.addVideoItem()
.setVideoUrl(videoUrl)
.setTitle(videoTitle)
.setHelpText(videoHelpText);

// Add multiple choice question
form.addMultipleChoiceItem()
.setTitle(questionTitle)
.setChoiceValues(choices)
.setRequired(false);

form.setPublished(false);

Logger.log('Form Edit URL: ' + form.getEditUrl());
}



Reference

addVideoItem()