2

I am trying to use the .NET APIs from Google https://code.google.com/p/google-api-dotnet-client/ https://www.nuget.org/packages/Google.Apis.Authentication/

As most of these APIs from Google require an oAuth token for you to fetch any data from them, I am struggling to get over this first hurdle.

My plan is to create a very simple .NET Web API that lists out my Google Analytic's accounts via the API which I can then in turn use with AngularJS to bind to a nice little view with the JSON returned from my WebAPI call.

The problem I mentioned is that there seems to be lots of different examples floating about and I can't seem to get any to to work. Either its out of date or the sample project doesn't compile etc...

From what I can understand I need to pass an Authenticator object to the BaseClient object which is in turn used for any Service API.

Below is a rough example I am trying to get to work, but currently fails and gets an error back from Google's API because I am not logged in/passing an oAuth token. Can anyone give me any pointers or advice please.

Thanks, Warren

[HttpGet]
public IEnumerable<Account> GetAccounts()
{
    var baseClient              = new BaseClientService.Initializer();
    baseClient.ApplicationName  = "Google Stats Example";
    baseClient.Authenticator    = null; //Unsure how to get the oAuth token

    AnalyticsService stats      = new AnalyticsService(baseClient);
    var accounts                = stats.Management.Accounts.List();
    var allAccounts             = accounts.Execute();

    return allAccounts.Items;
}

1 Answer 1

1

To create an authenticator you need a nuget package named "Google APIs OAuth2 Client Library" but i downloaded a nugget package named "Google.Apis.Oauth2.v2 Client Library". Similar names but not the same.

I was not able to find the correct one on nugget page. If you perform a search on that package it wont show up. I had to use Visual Studio Nugget searcher and activate "show prerealese packages" to install it.

Sign up to request clarification or add additional context in comments.

7 Comments

Thanks I think I have the same nugget installed and need to try the other one you are suggesting. Do you have a working example please that I can take a look at please?
Once that you install the right package you can use any example. Like this one: code.google.com/p/google-api-dotnet-client/source/browse/…
Thanks I have tried the ASP.NET WebForms example from that repo and it works fantastic. I just need to try and figure out how this would work in a ASP.NET WebAPI context.
What I want to do is to use the Google YouTube Analytics's API but for my own YouTube channel, hence I don't want users visiting the site to authenticate the API call using their own details. So the goal is to get some kind of permanent oAuth key or access token so I can do API calls to fetch my channel's YouTube statistics. Is this possible and if so how should I be going about it?
You can use authentication server type instead of user authentication. You can get a private key on your google console: var provider = new Google.Apis.Authentication.OAuth2.DotNetOpenAuth.AssertionFlowClient(Google.Apis.Authentication.OAuth2.GoogleAuthenticationServer.Description, certificate)
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.