我创建了一种方法,用C#中的Google API(最新版本)更新我的Blogger。我找到了一些解决方案,但运行应用程序时出错。有一个代码行,我无法执行。这部分代码在try {}中,但没有异常消息,catch {}中的代码不运行。我无法弄清楚问题是什么。我有2个测试解决方案,但没有一个适合我。请帮我看看问题是什么,我试着解决这个问题好几天......
对不起我的英语,我希望你能理解我的问题。
不同的解决方案标有#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 :(得分:2)
我想您在跟随代码时用数字字符串替换“BLOG_ID”, ... Uri blogFeedUri = new Uri(“http://www.blogger.com/feeds/”+“BLOG_ID”+“/ posts / default”);
右?