0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Youtube DATA APIで再生リストへの追加をNode.jsから行うメモ

Last updated at Posted at 2022-05-25

こちら記事 をもとにこんな感じでまとめてみました。

認証周りのコードを書いてないのであくまでも自分用メモです。

YYYYYYYYYに再生リストのID、XXXXXXXXXにYoutubeのVideoIdを入れれば動きます。

'use strict';

require('dotenv').config();

const tokenAuth = require('../libs/tokenAuth'); //トークンの認証
const {google} = require('googleapis');


const main = async params => {
    const credentials = process.env.YOUTUBE_DS_CREDENTIALS;
    const token = process.env.YOUTUBE_POS_BACKUP_TOKEN;
    
    const auth = tokenAuth(credentials, token);
    const youtube = google.youtube({version: 'v3', auth});

    try {
        const params = {
            part: 'id,snippet,contentDetails',
            requestBody: {
              snippet: {
                playlistId: 'YYYYYYYYY',
                position: 0,
                resourceId: {
                  videoId: 'XXXXXXXXX',
                  kind: 'youtube#video',
                },
              },
            }
        }
        const res = await youtube.playlistItems.insert(params);
        console.log(res.data);

    } catch (error) {
        console.log('The API returned an error: ' + error);
    }
}

main();

positionの箇所で再生リストのどこにいれるか指定できそうですね。

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?