youtube / api-samples

Code samples for YouTube APIs, including the YouTube Data API, YouTube Analytics API, and YouTube Live Streaming API. The repo contains language-specific directories that contain the samples.
5.51k stars 2.98k forks source link

.Net YouTube Report download returns headers only (no data) #113

Open paulbfelix opened 7 years ago

paulbfelix commented 7 years ago

The below code uses the .Net client library to create a report job, get a list of reports that have been generated, and download those reports. The problem I'm seeing is that the downloaded files contain only the hearders of the reports, no data.


`                    //Download the report     
                    //The Download method needs a resourceName.  Not sure how to get this so I'm parsing it out of the downloadUrl.               
                    string resourceName = report.DownloadUrl.Replace("https://youtubereporting.googleapis.com/v1/media/", "").Replace("?alt=media", "");
                    var getRequest = ytReportingService.Media.Download(resourceName);

                    using (var fileStream = new System.IO.FileStream(@filePath + reportTypeId + "_" + report.Id + ".csv", System.IO.FileMode.Create, System.IO.FileAccess.Write))
                    {
                        // Add a handler which will be notified on progress changes.
                        // It will notify on each chunk download and when the download is completed or failed.
                        getRequest.MediaDownloader.ProgressChanged += Download_ProgressChanged;
                        getRequest.Download(fileStream);
                    }`
cacciatc commented 7 years ago

Are you certain that there should be data for the time interval in those reports? From the YouTube docs under the Report Characteristics section:

YouTube does generate downloadable reports for days on which no data was available. Those reports will contain a header row but will not contain additional data.

paulbfelix commented 7 years ago

Thanks for the reply, cacciatc. You are correct. The reports that I unknowingly requested were not for the channel I was trying to collect data from. Because I use a "brand account" I needed to redo the oath2 process and select the appropriate brand instead of the owner of the brand. It would be very nice if this can be added to documentation somewhere. I was thinking that I might be a content owner (I'm not) which led me to this conclusion.