Fetching YouTube revenue data for content owners via HTML interface

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:

  1. Set up OAuth2 scopes for YouTube Analytics and partner access
  2. Created an HTML form to input CMS name, start date, and end date
  3. 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.

I’ve encountered this issue before. The ‘Query not supported’ error often stems from incorrect parameter formatting. In your case, try adjusting the ‘owner’ parameter to ‘ids’ as MiaDragon42 suggested. Additionally, ensure your date format is YYYY-MM-DD.

Another potential fix: modify your API call to include the ‘ids’ parameter separately:

let apiCall = gapi.client.youtubeAnalytics.reports.query({
  'ids': 'contentOwner==' + cms,
  'start-date': start,
  'end-date': end,
  'metrics': 'views,estimatedRevenue,adImpressions',
  'filters': 'video==__all__'
});

This structure aligns more closely with the current YouTube Analytics API requirements. If issues persist, verify your API credentials and ensure you’ve enabled the YouTube Analytics API in your Google Cloud Console project.

hey joec, i’ve dealt with similar issues before. one thing to check - make sure you’re using the right API version. the ‘owner’ parameter changed recently. try using ‘ids’ instead:

ids: ‘contentOwner==’ + cms,

also double-check your OAuth scopes. sometimes that trips people up. good luck!