views:

35

answers:

0

i try to insert a new sitemap to google using api, but i can't do it successful-_- this is the method

        var fullDomainUrl = "http://www.example.com/";
        var entry = new SitemapsEntry();
        entry.Id = new AtomId(fullDomainUrl + "sitemap.xml");
        entry.Categories.Add(new AtomCategory("http://schemas.google.com/webmasters/tools/2007#site-info", new AtomUri("http://schemas.google.com/g/2005#kind")));
        entry.SitemapType = "WEB";
        myService.Insert(new Uri(string.Format("https://www.google.com/webmasters/tools/feeds/{0}/sitemaps/", HttpUtility.UrlEncode(fullDomainUrl))), entry);

this will retuen a 400 bad request
and i try another method

var settings = new RequestSettings("TesterApp1", domain.GoogleAuthToken, CommonService.GetRsaPrivateKey(Context));
            var request = new WebmasterToolsRequest(settings);
            var sitemap = new Sitemap();
            sitemap.Id = fullDomainUrl + "sitemap.xml";
            sitemap.Categories.Add(new AtomCategory("http://schemas.google.com/webmasters/tools/2007#site-info", new AtomUri("http://schemas.google.com/g/2005#kind")));
            sitemap.SitemapType = "WEB";
            //request.AddSitemap(fullDomainUrl, sitemap);
            request.Insert(new Uri(string.Format("https://www.google.com/webmasters/tools/feeds/{0}/sitemaps/", HttpUtility.UrlEncode(fullDomainUrl))), sitemap);

this also return a 400 bad request
and then i try to use HttpWebRequest to post the atom to google,but it also return a 400 bad request( ̄▽ ̄")
i can insert/update site successful,but can;t insert a new sitemap..
does any can give a right code with .net?