2013-05-15 71 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

還是給了我同樣的錯誤:/ –