2013-05-15 65 views
0

我使用Google Blogger API以编程方式在我创建的博客中创建帖子。我使用下面的代码,试图创建一个新的职位,但它不断给我的错误:Google Blogger API - 无法创建帖子

*Execution of request failed: https://galeajean.blogspot.com/ ---> System.Net.WebException: The remote server returned an error: (405) Method Not Allowed.* 

我使用的代码是:

Service service = new Service("blogger", "blogger-example-1"); 
service.Credentials = new GDataCredentials(actualusername, actualpassword); 
GDataGAuthRequestFactory factory = (GDataGAuthRequestFactory)service.RequestFactory; 
factory.AccountType = "GOOGLE"; 
Uri blogPostUri = new Uri("http://galeajean.blogspot.com/"); 
AtomEntry createdEntry = PostNewEntry(service, blogPostUri); 

static AtomEntry PostNewEntry(Service service, Uri blogPostUri) 
    { 
     Console.WriteLine("\nPublishing a blog post"); 
     AtomEntry createdEntry = null; 
     if (blogPostUri != null) 
     { 
      // construct the new entry 
      AtomEntry newPost = new AtomEntry(); 
      newPost.Title.Text = "Marriage!"; 
      newPost.Content = new AtomContent(); 
      newPost.Content.Content = "<div xmlns='http://www.w3.org/1999/xhtml'>" + 
       "<p>Mr. Darcy has <em>proposed marriage</em> to me!</p>" + 
       "<p>He is the last man on earth I would ever desire to marry.</p>" + 
       "<p>Whatever shall I do?</p>" + 
       "</div>"; 
      newPost.Content.Type = "xhtml"; 
      newPost.Authors.Add(new AtomPerson()); 
      newPost.Authors[0].Name = "Elizabeth Bennet"; 
      newPost.Authors[0].Email = "[email protected]"; 

      createdEntry = service.Insert(blogPostUri, newPost); 

     } 
     return createdEntry; 
    } 

任何帮助将不胜感激你们。 ...在此先感谢;)

回答

1

好吧,我GT的prblm ... 问题是在你的博客blogPostUri .. 这应该是。

Uri blogPostUri = new Uri("http://www.blogger.com/feeds/" + blogID + "/posts/default"); 
+0

user2374372 ......我爱你:)尝试过了,它完美配合万分感谢! –

0

再次

newPost.Content.Type = "xhtml"; 

THN检查删除行...因为它可能可能你不张贴内容类型满足博客政策的stndrds ......它可以帮助...

+0

还是给了我同样的错误:/ –