Click here to Skip to main content
14,383,744 members
Rate this:
Please Sign up or sign in to vote.
See more:

Does anyone have any experience with Google.Apis.Webmasters.v3 (Nuget[^])?

I am having very little success with it >_<<br mode="hold" />
I want to have a stand alone app on my server that pulls the "impressions" fromn webmaster.Searchanalytics. I cannot get this to authenticate unless the windows user is logged into a google account with access (I would like it to authenticate itself), and when I am logged in I get nothing back. Just an ETag, a ResponseAggregationType and null Rows.

Most people appear to either not use the .net API, mostly because they are writing python or php, or are not using webmaster tools which appear to have a different level of authentication required.

I have posted on Googles forums but I doubt I'll see a response any tome soon.

So - Here is my code (If you wish to test then you will need to set up an api account and use a website you claim ownership of, i think )

using Google.Apis.Services;
using Google.Apis.Discovery.v1;
using Google.Apis.Discovery.v1.Data;
using Google.Apis.Webmasters.v3;
using Google.Apis.Webmasters.v3.Data;
using Google.Apis.Auth.OAuth2;

 public static WebmastersService AuthenicateService(string userName)
            ClientSecrets secrets = new ClientSecrets
                ClientId = OAuthClientId,
                ClientSecret = OAuthClientSecret
            string[] scopes = { WebmastersService.Scope.Webmasters };

                UserCredential credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                    new CancellationToken(false)

                var service = new WebmastersService(new BaseClientService.Initializer
                    HttpClientInitializer = credential,
                    ApplicationName = "ApiCall Sample",
                return service;
            catch (Exception exception)
                return null;
        public static async Task Run()
            var service = AuthenicateService(Username);
            foreach (var row in service.Features)
            var query = service.Searchanalytics.Query(
                new SearchAnalyticsQueryRequest
                    SearchType = "web",
                    //Dimensions = new[] {
                    //      "query"
                    //     },
                    StartDate = DateTime.Now.Date.ToString("yyyy-MM-dd"),
                    EndDate = DateTime.Now.AddDays(1).Date.ToString("yyyy-MM-dd")
                }, SiteUrl);

                var response = await query.ExecuteAsync();
                if (response.Rows != null)
                    foreach (ApiDataRow row in response.Rows)
            catch (Exception exception)
anu katari 8-Jun-17 23:18pm
Any leads on this please ?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100