Google .Net client library source code 5


Please Share

Google APIsThe Google .Net client library is an open source project. Open Source projects can be nice because they allow us as developers full access to the source code of a project. The main source code for the Google .Net client library can be found on GitHub google-apis-dotnet-client. However this is not the only source.

The dll’s behind the different APIs are dynamically built using a tool that requests all the information about the API from the Discovery  Services API.

The Google API Discovery Service is used by Google and others to build client libraries, IDE plugins, and other tools that interact with Google APIs. It provides a lightweight, JSON-based API that exposes machine-readable metadata about Google APIs, including:

 

The Discovery API supports the following:

  • A list of supported APIs.
  • A machine-readable “Discovery document” for each of the supported APIs that includes:
    • A list of API resource schemas based on JSON Schema.
    • A list of API methods and available parameters for each method.
    • A list of available OAuth 2.0 scopes.
  • Inline documentation of methods, parameters, and available parameter values.

In short the Discovery API returns all the information about the API in question, its just an API of APIs

API libraries source code

Using the following formula, you can find the link you need to download the source for any of the API .dlls.

Replace APINAME with the name of the API.
Replace APIVERSION with the version of the api.

https://developers.google.com/resources/api-libraries/download/APINAME/APIVERSION/csharp

The name of the API used in the Discovery API is not always the same as the common name the API is referred to. For instance we normally refer to drive as the Google Drive API but its just drive, it is the same with Google Analytics.

Example:

* https://developers.google.com/resources/api-libraries/download/analytics/v3/csharp
* https://developers.google.com/resources/api-libraries/download/drive/v2/csharp

You can check the Discovery API at the bottom of this page Discovery directory.list if you are unsure of the version or discovery name of the API.

NuGet Comments

A link to the package source code can also be found in the comments of most of the Google .APIs NuGet packages.   I am not sure if this is true for all of the packages, however most of them have a link to the package source in the comment section.   The Google.Apis.Analytics.v3 package has it added, if you are having trouble finding your source check the NuGet page a link may be found there.

The package source code is available at:

https://developers.google.com/resources/api-libraries/download/analytics/v3/csharp

Conclusion

The Google .Net client library is an open source project.  The core part of the project can be found on GitHub.  The source code for the dlls individual behind the individual APIs is dynamically built using a tool that access the discovery API.  You should now understand how to find the source code if you should have the need for it.

 

Please Share


Linda Lawton

About Linda Lawton

My name is Linda Lawton I have more than 20 years experience working as a developer and a database expert. I have been working with several of the Google APIs, since 2012. I helping others in the On-Line community to develop with the Google APIs, by creating my own blog www.daimto.com. This and my presence on a number of On-Line developer forums lead me to be noticed by the Google Analytics API development team. I was nominated for and recently became one of the first Google Developer Experts for Google Analytics.


Leave a comment

Your email address will not be published. Required fields are marked *

5 thoughts on “Google .Net client library source code

  • SriG

    I am using .Net 4.5. with the below code

    credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
    GoogleClientSecrets.Load(stream).Secrets,
    Scopes,
    “user”,
    CancellationToken.None, new FileDataStore(“C:/IIS_VRoot/cm/”, true)).Result;

    The above code is working in localhost when i am execute from visual studio. But the same code is not working if i host the application in IIS. Below are my observations,
    1. For the first time google get a consent from the user to give access gmail (if you are trying access gmail). This will open a default browser in the system and loads the consent page. Once the user accepts the consent, the above code will create a json file using “FileDataStore” with access and refresh tokens. This whole process works perfectly from localhost.
    2. But same code is not working if hosted in IIS. If we put the JSON that has access and refresh token that was generated using localhost by FileDataStore then even application hosted in IIS is also working.

    My guess is the part where “google’s api is trying to open default browser to load the consent screen” is not working when hosted the application in IIS. Do you have any fix for this ? Please let me know if i am missing anything. Thanks.

    • Linda Lawton
      Linda Lawton Post author

      I have seen this error before I dont have much experience with IIS my guess is its having problems writing the file to c:\iis_vRoot\cm or reading from that directory make sure it has the correct permissions. If you put the credentials file generated on your local system in that directory and its the same “user” it should load it. Unless of course it doesn’t have permissions to load from that directory.