我需要YouTube Analytics数据,而我正在使用googleapis npm包。
我的代码如下所示:
// configs
const ids = encodeURIComponent('contentOwner=={contentOwner_id}');
const startDate = '2018-01-01';
const endDate = '2018-01-31';
const metrics = 'views';
const dimensions = 'day';
const filters = encodeURIComponent('channel=={channel_id}');
const youtubeAnalytics = google.youtubeAnalytics('v2');
// call endpoint
youtubeAnalytics.reports
.query({
ids,
'start-date': startDate,
'end-date': endDate,
metrics,
dimensions,
filters,
auth,
})
.then(results => {
console.log(results);
})
.catch(error => {
console.log(error); // error is cought here
});

我收到错误:
[ { message: 'Could not parse content (contentOwner%3D%3DcontentOwner_id) of field ids.', domain: 'global', reason: 'badRequest' } ]
如果我不使用encodeURIComponent,我会收到另一条错误消息:
[{message:'必需',域名:'全球',原因:'必需' }]}
** ------ 更新 ------ **
我更改了youtubeAnalytics的版本:
// before: const youtubeAnalytics = google.youtubeAnalytics('v2');
const youtubeAnalytics = google.youtubeAnalytics('v1beta1');

解决了这个问题!我需要更改什么才能使用v2?