Pergunta

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 :)

Foi útil?

Solução

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;
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top