Search code examples
c#.netvb.netgoogle-apiyoutube-api

How to start using Google API v3?


I downloaded and compiled the official Google's API for .Net successful removing some incompatible referenced projects (Mobile WP81 projects).

Now, I'm trying to getting started with my very first steps to use the API, I'm following the official examples of YouTube API, the big problem I have is that I can't reproduce the example because these Namespaces are missing ...so I can't import them:

Imports Google.Apis.Authentication
Imports Google.Apis.Authentication.OAuth2
Imports Google.Apis.Authentication.OAuth2.DotNetOpenAuth
Imports Google.Apis.Samples.Helper
Imports Google.Apis.Youtube.v3
Imports Google.Apis.Youtube.v3.Data

These are the assemblies that I have compiled and referenced in my project:

Google.Apis.Auth.dll
Google.Apis.Auth.PlatformServices.dll
Google.Apis.Core.dll
Google.Apis.dll
Google.Apis.PlatformServices.dll

Plus these external dependencies:

BouncyCastle.Crypto.dll
log4net.dll
Newtonsoft.Json.dll
Zlib.Portable.dll

What I'm missing?.

UPDATE

I think that exists two problems, the first is that seems the example is old because the Namespace Google.Apis.Authentication seems has changed to Google.Apis.Auth, however, I still can't find the equivalent Namespaces for these:

Google.Apis.Authentication.OAuth2.DotNetOpenAuth
Google.Apis.Samples.Helper
Google.Apis.Youtube.v3
Google.Apis.Youtube.v3.Data

And the second problem, seems that I need to download an additional Google's library/dependency to obtain the YouTube API then be able to see the YouTube Namespaces, I think so, but I don't know where to download.


Solution

  • Note: This solution has been tried and tested

    First and foremost I myself did not go to Github to get the API's for .Net. One reason and usually has been a problem at least for me is because of trying to figure out dependencies and such. With that in mind I recommend using NuGet and use the Package Manager Console. The reason is simple, you do not have to worry about compiling source, reference issue's with other libraries, dependencies etc...

    How Did I get It To Work?

    Please follow these steps as not only getting the API to actually work, but I did find out that there are more issue's with the official example you provided above (not your fault). I believe its a change in the newer version, specifically the YouTubeService class. Haven't had much time knocking this one down or yet report it to them, but is an issue with awaitand ExecuteAsync... Anyway's let get to work.

    1. Get a new C# project going at least 4.5; I did a C# form application. The one you referenced was console, but will still print out information in the Visual Studio Ouput Window. Save this project off and run it at least one time; creates the bin\debug directory that you need before using the Package Manager for NuGet.
    2. Go to Tools --> NuGet Package Manager --> Package Manager Console.
    3. Once loaded copy and paste: Install-Package Google.Apis.YouTube.v3 and then hit enter to download the package. You will see it download everything and should be good to go. You will notice a new file under your project: packages.config which is related to this package, do not remove it. Also here is the link to that NuGet, grab it HERE

    At this point, just re-build and run your program. Everything should be great to go at this point.

    This end's your actual Issue I have addressed

    Now on to the issue's I came across using the provided (official) example.

    1. First you need to get the client_secrets.json and you can do that through the Developer Console. Download the json file and put it in your bin\debug directory. You can worry about placing it elsewhere later...
    2. In that example find the code below:

      // Retrieve the contentDetails part of the channel resource for the authenticated user's channel. var channelsListResponse = await channelsListRequest.ExecuteAsync();

    You need to remove: await keyword and ExecuteAsync() to: Execute(). This is the problem I came across and it was a pain in the a$$. It would execute, but I never received a response back, never, never... That was until I removed the listed above and replaced them.

    1. There is one more place you need to modify as well. Please see below...

    // Retrieve the list of videos uploaded to the authenticated user's channel. var playlistItemsListResponse = await playlistItemsListRequest.ExecuteAsync();

    You need to do the same for this line as well as I said above. Once done, you should be able to run the application and get result's back.

    I hope you find this useful and relieving as much as I did. Also as I mentioned, this isn't reported to Google yet about the ExecuteAsync issue. I hope someone reports this so it can be addressed and fixed.

    Happy Coding!

    Reference To Await

    enter image description here