0

我正在做一个项目,我想在其中集成 Google Webmaster Tools Api。我有一个 webmastertool 帐户,我想构建一个程序,每天将我的网站的所有信息动态提取到 Excel 表中。我搜索但没有找到任何好的文档来在 C# 中实现 API。

谁能告诉我在哪里可以找到更好/更多的文档?

4

1 回答 1

1

你当然可以从使用这个开始:http ://code.google.com/p/google-gdata/

并使用一些代码,例如:

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);

    }
}

完整的 Java 参考可以在这里找到:https ://developers.google.com/webmaster-tools/docs/2.0/developers_guide_java

我知道它不是 C#,但它会给你一个很好的起点。

于 2013-03-15T23:22:51.120 回答