Thursday, March 15, 2012

[YouTube-API] Re: Using C# to retrieve YouTube Insights

Hello,

Feed<Video> video = request.Get<Video>(new
YouTubeQuery(String.Format("http://gdata.youtube.com/feeds/api/videos/
{0}", videoId)));
foreach (AtomLink link in
video.Entries.ElementAt(0).YouTubeEntry.Links)
{
if (link.Rel == "http://gdata.youtube.com/schemas/
2007#insight.views
")
{
// The URL is in link.HRef.ToString()
}
}

This assumes that you have an authenticated request object and that
videoId is a video that belongs to the authenticated user.

Cheers,
-Jeff Posnick, YouTube API Team
groups.google.com/group/youtube-api-gdata | apiblog.youtube.com |
@YouTubeDev

On Mar 13, 3:23 pm, Chiat Development1 <chiatd...@gmail.com> wrote:
> Well Jeff,
>
> has anyone ever used the .Net API to retrieve insights? I'm providing the
> e-mail address
> and password of the account.  The token is the developer key.
>
> The Video objects that come back  from the call
>
> Feed<Video> videoFeed = request.Get<Video>(new Uri(feedUrl));
>
> Do not appear to have any Link collections or lists that can be interrogated.
>
> Is this an omission on the part of the providers of the YouTube .Net
> interface, or am I doing something
> incorrect? Can you have one of your .NET API developers advise me where to
> find the Link objects
> within the Feed<Video> list?
>
> Thank you.
>
> ChDev.
>
>
>
>
>
>
>
> On Tue, Mar 13, 2012 at 10:53 AM, Jeffrey Posnick <je...@google.com> wrote:
> > Hello,
>
> >  I don't have any C# code readily available, but I can tell you what
> > you're doing wrong. You should not be manually creating YouTube
> > Insight URLs. You can't do it. You seem to be using your YouTube
> > authentication token as the value of the "token=" URL parameter, and
> > sticking your username and password in the URL for good measure, but
> > that's completely the wrong approach. The Insight URL is uniquely
> > generated by the API and exposed in an authenticated request for a
> > video entry by that entry's owner, in a <link> element. This is
> > explained at
>
> >https://developers.google.com/youtube/2.0/developers_guide_protocol_i...
>
> >  Again, you can't manually create the URL. The only time you need to
> > modify the automatically generated URL at all is if you want to modify
> > the user_starttime or user_endtime parameters, which is also covered
> > in the docs.
>
> > Cheers,
> > -Jeff Posnick, YouTube API Team
> > groups.google.com/group/youtube-api-gdata | apiblog.youtube.com |
> > @YouTubeDev
>
> > On Mar 12, 6:09 pm, ChDev <chiatd...@gmail.com> wrote:
> > > Does any one have working code for retrieving Insights data for each
> > video
> > > in a channel?
>
> > > 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:
>
> > >https://insight.youtube.com/video-analytics/csvreports?query=VIDEO_ID...
>
> > > 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("&region=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 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.

--
You received this message because you are subscribed to the Google Groups "YouTube APIs Developer Forum" group.
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