创建实时广播时出错 - NodeJS 库



我正在尝试使用 nodejs 客户端库创建实时广播,但出现以下错误:

{ Error: Title is required
    at Request._callback   code: 400,
.
.
.
  errors: 
   [ { domain: 'youtube.liveBroadcast',
       reason: 'titleRequired',
       message: 'Title is required',
       extendedHelp: 'https://developers.google.com/youtube/v3/live/docs/liveBroadcasts/insert#request_body' } ] }

它正在 API 资源管理器上工作,这让我迷失了这个。这是代码:

var google = require('googleapis');
var OAuth2 = google.auth.OAuth2;
var youtube = google.youtube('v3');
var oauth2Client = new OAuth2(
  'xxxx', //CLIENT_ID
  'xxxx', //MY_CLIENT_SECRET,
  'http://localhost:3000/api/integrations/youtube'//YOUR_REDIRECT_URL
);
oauth2Client.setCredentials({
  access_token: "xxxx",
  refresh_token: "xxxx"
});
broadcastParams = {
    "auth": oauth2Client,
    "part": "snippet,status,contentDetails",
    "snippet": {
        "title": "Testing NodeJS",
        "scheduledStartTime": "2017-02-20T14:00:00.000Z",
        "scheduledEndTime": "2017-02-20T15:00:00.000Z",
    },
    "status": {
        "privacyStatus": "private",
    },
    "contentDetails": {
        "monitorStream": {
            "enableMonitorStream": true,
        }
    }
};

youtube.liveBroadcasts.insert(broadcastParams,  
function(err,broadcast) {
    if (err) {
        return console.log('Error creating broadcast: ', err);
    }
    console.log('Broadcast = ' + JSON.stringify(broadcast));
});

感谢您的帮助!

解决了

我的广播参数不正确。我错过了"资源"。以下是现在正在运行的代码:

var google = require('googleapis');
var OAuth2 = google.auth.OAuth2;
var youtube = google.youtube('v3');
var oauth2Client = new OAuth2(
  'xxxx', //CLIENT_ID
  'xxxx', //MY_CLIENT_SECRET,
  'http://localhost:3000/api/integrations/youtube'//YOUR_REDIRECT_URL
);
oauth2Client.setCredentials({
  access_token: "xxxx",
  refresh_token: "xxxx"
});
broadcastParams = {
    "auth": oauth2Client,
    "part": "snippet,status,contentDetails",
    "resource": {
        "snippet": {
            "title": "Tesing NodeJS 123",
            "scheduledStartTime": "2017-02-20T14:00:00.000Z",
            "scheduledEndTime": "2017-02-20T15:00:00.000Z",
        },
        "status": {
            "privacyStatus": "private",
        },
        "contentDetails": {
            "monitorStream": {
                "enableMonitorStream": true,
            }
        }
    }
};

youtube.liveBroadcasts.insert(broadcastParams,  function(err,broadcast) {
    if (err) {
        return console.log('Error creating broadcast: ', err);
    }
    console.log('Broadcast = ' + JSON.stringify(broadcast));
});

相关内容

  • 没有找到相关文章

最新更新