0

I am trying to display YouTube analytics data in a .Net application (Asp.net MVC 4 to be specific) using the google api .net client

The only sample I could find for this was a JavaScript sample located here for the most parts I was able to recreate the code in .Net, The only problem is that I don't seem to be able to find the counterpart for this lines of code which returns a list of Channels for the authenticated user:

 var request = gapi.client.youtube.channels.list({
      // "mine: true" indicates that you want to retrieve the authenticated user's channel.
      mine: true,
      part: 'id,contentDetails'
    }); 

which should be then used here in my code:

 var request = youtubeAnalyiticsService.Reports.Query(
                    "channel=="+ channelId, fromDate, toDate, 
                    "views,likes,dislikes" // metrics to include in report 
                    );

What I currently do to get it to work is to copy and paste the channel Id here and therefore "hard-code" it which is not practical in this my case and used only for testing purposes.

Hopefully I'm wrong but after searching for hours I think that the .Net API might be missing this part, can anyone confirm this? and if true are there any alternatives for doing this in the .net application?

I also guess that there might be a straightforward way to just use that part of the JavaScript code in the .net application but I'm not sure how!

Any help, hint or clarification would be much appreciated :)

Bahador Izadpanah
  • 1,866
  • 1
  • 14
  • 13
  • does this work when you use the hardcoded Channel Id? if so then replace that channel id with a Parameter.. – MethodMan Jan 23 '13 at 09:12
  • @DJKRAZE Yes, it does work that way so I changed the code as you suggested, thanks – Bahador Izadpanah Jan 23 '13 at 09:27
  • glad that I could provide you with a simple fix – MethodMan Jan 23 '13 at 09:41
  • @DJKRAZE sorry if I caused any confusion, but the problem still exists my answer was to your question asking whether It works if I hard-code the ChannelId or not, the problem is that I'm not able to find a way to get the user's channel Id for the current user. – Bahador Izadpanah Jan 23 '13 at 10:18
  • yes your question was misleading I will delete my answer.. – MethodMan Jan 23 '13 at 10:20
  • look at this link for some references https://developers.google.com/youtube/2.0/developers_guide_protocol_channel_search | this might help as well http://www.codeproject.com/Articles/207284/Displaying-Videos-from-YouTube-Channel-in-ASP-NET – MethodMan Jan 23 '13 at 10:22
  • I've already read most of the provided documentations on googlcode in this regard and the only thing I'm missing is the line I mentioned in my question, Thanks anyway though I really appreciate all the efforts – Bahador Izadpanah Jan 23 '13 at 10:29

1 Answers1

2

This should work, assuming you've already got OAuth 2 setup and youtube is a YouTubeService object that's been properly authorized:

ChannelsResource.ListRequest channelsListRequest = youtube.Channels.List("id");
channelsListRequest.Mine = true;
ChannelListResponse channelsListResponse = channelsListRequest.Fetch();
string channelId = channelsListResponse.Items[0].Id;
Jeff Posnick
  • 53,580
  • 14
  • 141
  • 167