Question

I'm working a project in which I want to integrate the Google Webmaster Tools Api. I have a webmastertool account and I want to build a program that will dynamically extract all the information for my sites into an excel sheet every day. I searched but did not find any good documentation to implement the API in C#.

Can anyone tell me where to find better/more documentation about it?

Was it helpful?

Solution

You can certainly start by using this: http://code.google.com/p/google-gdata/

and use some code like:

class Program
{
    private static int lastIndex = 0;

static int DumpCrawlErrors(int startFrom)
{

    WebmasterToolsService service = new WebmasterToolsService("exampleCo-exampleApp-1");
    service.setUserCredentials("myusername", "mypassword");
    string url = HttpUtility.UrlEncode("http://example.com");
    string slug = Utilities.EncodeSlugHeader("https://www.google.com/webmasters/tools/feeds/" + url + "/crawlissues/?start-index=" + startFrom + "&max-results=100");

    CrawlIssuesQuery feedQuery = new CrawlIssuesQuery(slug);

    CrawlIssuesFeed feed = service.Query(feedQuery);

    StringBuilder results = new StringBuilder();
    foreach (CrawlIssuesEntry crawlIssuesEntry in feed.Entries)
    {

        string crawlUrl = ((XmlExtension)crawlIssuesEntry.ExtensionElements[2]).Node.InnerText;
        if (crawlIssuesEntry.IssueType == "not-found")
        {
            results.AppendLine(string.Format("{0}\t{1}\t{2}\t{3}", crawlUrl, crawlIssuesEntry.IssueType, crawlIssuesEntry.IssueDetail, crawlIssuesEntry.LinkedFrom));

        }
    }

    System.IO.File.AppendAllText("result.log", results.ToString());

    return feed.Entries.Count;
}

static void Main(string[] args)
{
    lastIndex = 0;
    int numberOfEntriesAdded = 0;
    do
    {
        numberOfEntriesAdded = DumpCrawlErrors(lastIndex + 1);
        lastIndex += numberOfEntriesAdded;
    } while (numberOfEntriesAdded == 100);

    }
}

The complete Java reference can be found here:https://developers.google.com/webmaster-tools/docs/2.0/developers_guide_java

I know it is not C#, but it'll give you a good starting point.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top