2011-06-28 31 views
3

我創建了一個用C#中的Google API(最新版本)更新Blogger的方法。我找到了一些解決方案,但運行應用程序時出現錯誤。有一個codeline,我不能執行。這部分代碼在try {}中,但沒有異常消息,並且catch {}中的代碼不運行。我無法弄清楚有什麼問題。我有2個解決方案來測試,但他們都不適合我。請幫我找出最新的問題,我試着解決這個問題...如何通過C#中的Google API發佈到Blogger#

對不起,我的英語,我希望你能理解我的問題。

不同的解決方案標有#1和#2。

public static bool AddPost(string title, string bodyHTML, string[] labels, string username, string password, string blogurl) 
    { 
     Service service = new Service("blogger", "Updater"); 
     service.Credentials = new GDataCredentials(username, password); 
     AtomEntry newPost = new AtomEntry(); 
     newPost.Title.Text = title; 
     newPost.Content = new AtomContent(); 
     newPost.Content.Content = bodyHTML; 
     newPost.Content.Type = "html"; 
     foreach (string label in labels) 
     { 
      AtomCategory cat = new AtomCategory(); 
      cat.Scheme = new Uri("http://www.blogger.com/atom/ns#"); 
      cat.Term = label; 
      newPost.Categories.Add(cat); 
     } 
     AtomEntry response = null; 
     try 
     { 
      #1------------------------------------------------------ 
      Uri blogFeedUri = new Uri("http://www.blogger.com/feeds/" + "BLOG_ID" + "/posts/default"); 
      response = service.Insert(blogFeedUri, newPost); 

      #2------------------------------------------------------ 
      response = service.Insert(new Uri(blogurl + "feeds/posts/default"), newPost); 
     } 
     catch (GDataRequestException exception) 
     { 
      if (exception.ResponseString == "Blog has exceeded rate limit or otherwise requires word verification for new posts") 
      { 
       return false; 
      } 
      else 
      { 
       throw exception; 
      } 
     } 
     if (response == null) 
     { 
      throw new Exception("Something went wrong"); 
     } 
     return true; 
    } 
+0

爲什麼不嘗試Google Blogger API v3?在VS中用NuGet安裝它! – GaryNg

回答

2

我想你用數字串代替 「BLOG_ID」 在下面的代碼, ... 烏里blogFeedUri =新的URI( 「http://www.blogger.com/feeds/」 + 「BLOG_ID」+「/ posts/default」);

對不對?

+0

當我將Google API從1.4升級到1.80時,我遇到了同樣的問題。在Blogger開發者的博客中找到了這些文章。 http://code.blogger.com/2011/06/clarifying-recent-changes-to-bloggers.html –

相關問題