I'm attempting to retrieve YouTube insights using C#. I have been able to retrieve video IDs
with the code below, but I cannot retrieve the insights. I am hoping that by using the video ID
I can do a get on the following URL:
Though this approach (and URL) doesn't seem to work.
Any ideas? A specific C# code example (that works) would be invaluable.
-------------my code sample ----------------
public class UnixTime
{
public static string ToUnixTime(DateTime dateTime)
{
return (Math.Round((dateTime - new DateTime(1970, 1, 1, 0, 0, 0).ToLocalTime()).TotalSeconds, 0)).ToString() ;
}
}
public void PrepareAndDownloadFile(string username, string password, string token, string channel, string destination)
{
YouTubeRequestSettings settings = new YouTubeRequestSettings(channel, token, username, password);
YouTubeRequest request = new YouTubeRequest(settings);
string feedUrl = String.Format("http://gdata.youtube.com/feeds/api/users/{0}/uploads?v=2", channel);
Feed<Video> videoFeed = request.Get<Video>(new Uri(feedUrl));
foreach (Video video in videoFeed.Entries)
{
StringBuilder url = new StringBuilder();
url.Append("https://insight.youtube.com/video-analytics/csvreports");
url.Append(String.Format("?query={0}", video.Id));
url.Append("&type=v");
url.Append(String.Format("&starttime={0}", UnixTime.ToUnixTime(DateTime.Now.AddDays(SINCE_OFFSET))));
url.Append(String.Format("&endtime={0}", UnixTime.ToUnixTime(DateTime.Now.AddDays(UNTIL_OFFSET))));
url.Append("®ion=world");
url.Append("&hl=en_US");
url.Append(String.Format("&userName={0}", username));
url.Append(String.Format("&password={0}", password));
url.Append(string.Format("&token={0}", token));
// make Http Request here given the new url.
dynamic rows = GetPath(url.ToString());
processor.WriteRows(destination, rows);
}
}
-------------end sample ----------------
You received this message because you are subscribed to the Google Groups "YouTube APIs Developer Forum" group.
To view this discussion on the web visit https://groups.google.com/d/msg/youtube-api-gdata/-/PxMDez7j9nQJ.
To post to this group, send email to youtube-api-gdata@googlegroups.com.
To unsubscribe from this group, send email to youtube-api-gdata+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/youtube-api-gdata?hl=en.
No comments:
Post a Comment