2011-06-28 24 views
3

C#でGoogle API(最新版)でBloggerを更新する方法を作成しました。私はいくつかの解決策を見つけましたが、アプリの実行中にエラーが発生しました。私が実行できないコードラインがあります。このコード部分は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

私はあなたのコード、 ... ウリblogFeedUri =新しいウリは次の数の文字列で "BLOG_ID" を交換することを想定( "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 –

関連する問題