I’m working on a project to show YouTube analytics for content owners using an HTML form. I’ve tweaked a sample app I found online, but I’m running into issues.
Here’s what I’ve done so far:
- Set up OAuth2 scopes for YouTube Analytics and partner access
- Created an HTML form to input CMS name, start date, and end date
- Made a function called
getChannelStats
that uses the YouTube Analytics API
My code looks something like this:
function getChannelStats(cmsName, beginDate, endDate) {
let cms = cmsName.value;
let start = beginDate.value;
let end = endDate.value;
let apiCall = gapi.client.youtubeAnalytics.reports.fetch({
'begin-date': start,
'end-date': end,
owner: 'contentOwner==' + cms,
stats: 'views,revenue,adImpressions',
filters: 'contentStatus==owned'
});
apiCall.execute(function(result) {
if (result.error) {
console.error(result);
} else {
console.log('Data fetched successfully');
}
});
}
The API Explorer works fine with these parameters, but when I run it from my form, I get a ‘Query not supported’ error. Any ideas on how to fix this? I’m stuck and can’t move forward to display the results on the page.