api-samples icon indicating copy to clipboard operation
api-samples copied to clipboard

.Net Youtube Analytics API Vague Error Message

Open leijae opened this issue 4 years ago • 1 comments

Using the .Net youtube analytics client, I get the following error when with the attached executed code. This query works in the "Try It" section of the Youtube Analytics and Reporting documenation

// ERROR MESSAGE Google.Apis.Requests.RequestError Required [400] Errors [ Message[Required] Location[ - ] Reason[required] Domain[global] ]

// CODE BEGINS HERE var youtubeAnalyticsService = new YouTubeAnalyticsService(new BaseClientService.Initializer() { HttpClientInitializer = credential, ApplicationName = "MyApp" });

            var query = youtubeAnalyticsService.Reports.Query();
            query.EndDate = DateTime.Today.ToString("yyyy-MM-dd");
            query.StartDate = DateTime.Today.AddDays(-30).ToString("yyyy-MM-dd");
            query.Ids = "channel==MINE";
            query.Metrics = "views,comments,likes,dislikes,estimatedMinutesWatched,averageViewDuration,subscribersGained";
            query.Dimensions = "day";
            query.Sort = "day";

            var result = await youtubeAnalyticsService.Reports.Query().ExecuteAsync(); 

There doesn't seem to be any other way to assign values to the ReportsQuery object. Unless I'm missing something...

leijae avatar Sep 30 '21 19:09 leijae

I think it might be because the startdate and enddate parameters are hard-coded incorrectly. v1 of the API uses start-date and end-date while v2 switched to startDate and endDate....

that's a possible fix.

I ended up getting this whole thing working just using httpclient

leijae avatar Oct 01 '21 18:10 leijae