Ebeo / google-gdata

Automatically exported from code.google.com/p/google-gdata
0 stars 0 forks source link

can't insert new site with PreferredDomain and can't update with 400 error #380

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
i use this to insert a new site to web master
            var authFactory = new GAuthSubRequestFactory("sitemaps", "TesterApp")
            {
                Token = domain.GoogleAuthToken,
                PrivateKey = CommonService.GetRsaPrivateKey(Context)
            };
            var myService = new WebmasterToolsService(authFactory.ApplicationName) { 
RequestFactory = authFactory };           

            var entry = new SitesEntry();
            entry.Content.Src = "http://"+domain.DomainURL+"/";
            entry.Content.Type = "text/plain";
            entry.PreferredDomain = "preferwww";
            var method = new VerificationMethod("htmlpage", "true");
            entry.VerificationMethod = method;         
            myService.Insert(new Uri(SitesQuery.HttpsFeedUrl), entry);

these code can insert a new site successfully, but the PreferredDomain and 
VerificationMethod 
can't insert, when i get the sites with these code
            var authFactory = new GAuthSubRequestFactory("sitemaps", "TesterApp")
            {
                Token = domain.GoogleAuthToken,
                PrivateKey = CommonService.GetRsaPrivateKey(Context)
            };

            var myService = new WebmasterToolsService(authFactory.ApplicationName) { 
RequestFactory = authFactory };

            SitesQuery feedQuery = new SitesQuery();
            SitesFeed feed = myService.Query(feedQuery);

            if(feed.Entries.Count > 0)
            {
                var entry = (SitesEntry)feed.Entries[0];

                var Verified = bool.Parse(entry.Verified);

                //entry.PreferredDomain = "preferwww";
                //SitesEntry updatedEntry = myService.Update(entry);
            }
the PreferredDomain is null and the VerificationMethod is metatag type,when i 
try to update 
the PreferredDomain using myService.Update(entry), it has a exception(400 error)

What version of the product are you using? On what operating system?
i use the new version from the svn, windows 2003+.net 2.0

Original issue reported on code.google.com by wingo...@gmail.com on 1 May 2010 at 7:13

GoogleCodeExporter commented 9 years ago
the update error
[WebException: Remote server returned an error: (400) Bad Request.]
   System.Net.HttpWebRequest.GetResponse() +5314029
   Google.GData.Client.GDataRequest.Execute() +77

[GDataRequestException: Execution of request failed: 
https://www.google.com/webmasters/tools/feeds/sites/http://www.example.com/]
   Google.GData.Client.GDataRequest.Execute() +162
   Google.GData.Client.GDataGAuthRequest.Execute(Int32 retryCounter) +402
   Google.GData.Client.GDataGAuthRequest.Execute() +10
   Google.GData.Client.Service.EntrySend(Uri feedUri, AtomBase baseEntry, 
GDataRequestType type, AsyncSendData data) +190
   Google.GData.Client.Service.Update(AtomEntry entry, AsyncSendData data) +79
   Google.GData.Client.Service.Update(TEntry entry) +46

Original comment by wingo...@gmail.com on 1 May 2010 at 7:18

GoogleCodeExporter commented 9 years ago
i find it's my error, the update fail is because the site is not 
verified,sorry( ̄▽ ̄")

Original comment by wingo...@gmail.com on 1 May 2010 at 4:48

GoogleCodeExporter commented 9 years ago
after 2 days working on this( ̄▽ ̄"), i find this error is beacuse the url 
which 
post/put to google is not correct. these raw url are all has the urlencode 
siteid 
like http%3A%2F%2Fwww%2Eexample%2Ecom%2F,,but the .net uri.AbsoluteUri has a 
bug and 
it will    convert %2f to slash(/),so the url is error,microsoft says will fix 
this 
in .net 4.0,i don't test in this verision.
in the method UpdateSiteEntry in WebmasterToolsRequest, i find a method 
CreateCustomUri which says to fix this bug, and with debug i find the last url 
to 
post to google is like this : http%253A%252F%252Fwww.example.com%252F , and 
google 
accept it,,but when i try to add a sitemap using AddSitemap in 
WebmasterToolsRequest 
, it also call the method CreateCustomUri but google don't accept it, so what 
can i 
do? just wait microsoft to fix or?

Original comment by wingo...@gmail.com on 3 May 2010 at 4:52

GoogleCodeExporter commented 9 years ago
we are working on this. If you use the request model it will actually 
successfully post to the correct URL, but 
there is problem with one element that is not persisted correctly yet...

Original comment by fman...@gmail.com on 5 May 2010 at 8:41

GoogleCodeExporter commented 9 years ago
yes, i have update PreferredDomain successfully using the request model, but 
now i can't 
insert a sitemap to a site, the error catched by GDataRequestException is 
"Invalid request 
URI", and i found a extension method workarounds to fixed .net uri error in 
here: 
http://connect.microsoft.com/VisualStudio/feedback/details/94109/system-uri-cons
tructor-
evaluates-escaped-slashes-and-removes-double-slashes
it really works, after fixed this there is another error returned "Missing 
entry type", and 
my method insert sitemap is :
                 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(SitemapsQuery.HttpsFeedUrl), entry);
                try
                {
                    Uri uro3 = new 
Uri(string.Format("https://www.google.com/webmasters/tools/feeds/{0}/sitemaps/",

HttpUtility.UrlEncode(fullDomainUrl)));
                    uro3.LeaveDotsAndSlashesEscaped();
                    //myService.EntrySend(uro3, entry, GDataRequestType.Insert);
                    myService.Insert(uro3, entry);
                }
                catch (GDataRequestException e)
                {
                    Response.Write(e.ResponseString);
                    //throw;
                }
and also i use the request model, it return the same error, is there any 
solution to insert 
sitemap?

Original comment by wingo...@gmail.com on 5 May 2010 at 8:58

GoogleCodeExporter commented 9 years ago

Original comment by ccherub...@google.com on 29 Mar 2011 at 10:19