【问题标题】:Integrating the Google Webmaster Tools api to extract data from my sites集成 Google Webmaster Tools api 以从我的站点中提取数据
【发布时间】:2014-12-26 20:43:26
【问题描述】:

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

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

【问题讨论】:

    标签: google-search-console


    【解决方案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#,但它会给你一个很好的起点。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-03-30
      • 1970-01-01
      • 2013-07-14
      • 1970-01-01
      • 1970-01-01
      • 2021-03-29
      • 2013-01-02
      • 1970-01-01
      相关资源
      最近更新 更多