YouTube API - 分析v 1报告返回500内部服务器错误

时间:2014-04-01 15:40:24

标签: c#-4.0 google-analytics youtube-analytics

大家好我所拥有的应用程序可以提取YouTube分析数据,但有时无法正常运行。详细信息如下,代码为

for (int ISOCountryCode = 0; ISOCountryCode < ds.Tables[0].Rows.Count; ISOCountryCode++)
                {
                    //validation to check if date is null
                    string strdimensions = "day";
                    string strmetrics = "views,comments,favoritesAdded,favoritesRemoved,likes,dislikes,shares,estimatedMinutesWatched,averageViewDuration,averageViewPercentage,annotationClickThroughRate,annotationCloseRate,subscribersGained,subscribersLost,uniques";
                    string strstartdate = Convert.ToDateTime(WeekStartDate).ToString("yyyy-MM-dd");
                    string strenddate = Convert.ToDateTime(WeekEndDate).ToString("yyyy-MM-dd");

                    string DownloadURL = string.Format("https://www.googleapis.com/youtube/analytics/v1/reports?ids=channel==" + ChannelID + "&start-date=" + strstartdate + "&end-date=" + strenddate + "&metrics=" + strmetrics + "&key=KE9gM-4_tgmVw3L3QaMSeR-G4X5vr7tA&access_token=" + token + "&dimensions=" + strdimensions + "&alt=csv&filters=country==" + ds.Tables[0].Rows[ISOCountryCode]["ISOCode"].ToString());
                    urlDownload.Download(DownloadURL, "Z:\\InsightData\\ChannelData\\UnZipFilesFldr\\" + ChannelID + "_world_" + ds.Tables[0].Rows[ISOCountryCode]["ISOCode"].ToString() + ".csv");

                    strdimensions = "day,operatingSystem,deviceType";
                    strmetrics = "estimatedMinutesWatched,views";

                    DownloadURL = string.Format("https://www.googleapis.com/youtube/analytics/v1/reports?ids=channel=={2}&start-date=" + strstartdate + "&end-date=" + strenddate + "&metrics=" + strmetrics + "&key=KE9gM-4_tgmVw3L3QaMSeR-G4X5vr7tA&access_token={0}&dimensions=" + strdimensions + "&alt=csv&filters=country=={1}", token, ds.Tables[0].Rows[ISOCountryCode]["ISOCode"].ToString(), ChannelID);
                    urlDownload.Download(DownloadURL, "Z:\\InsightData\\ChannelData\\UnZipFilesFldr\\" + ChannelID + "_world-device_" + ds.Tables[0].Rows[ISOCountryCode]["ISOCode"].ToString() + ".csv");

                    strdimensions = "day,operatingSystem,deviceType";
                    strmetrics = "estimatedMinutesWatched,views";

                    DownloadURL = string.Format("https://www.googleapis.com/youtube/analytics/v1/reports?ids=channel=={2}&start-date=" + strstartdate + "&end-date=" + strenddate + "&metrics=" + strmetrics + "&key=KE9gM-4_tgmVw3L3QaMSeR-G4X5vr7tA&access_token={0}&dimensions=" + strdimensions + "&alt=csv&filters=country=={1}", token, ds.Tables[0].Rows[ISOCountryCode]["ISOCode"].ToString(), ChannelID);
                    urlDownload.Download(DownloadURL, "Z:\\InsightData\\ChannelData\\UnZipFilesFldr\\" + ChannelID + "_world-deviceType_" + ds.Tables[0].Rows[ISOCountryCode]["ISOCode"].ToString() + ".csv");
                }

The Code in the urlDownload.Download is :-

HttpWebRequest wr = (HttpWebRequest)WebRequest.Create(strURLFileandPath);
                HttpWebResponse ws = (HttpWebResponse)wr.GetResponse();
                Stream str = ws.GetResponseStream(); - > Line Of Error

在它要求响应流的最后一行,它出错并说出&#34; 500内部服务器错误&#34;

0 个答案:

没有答案