Reputation: 53
I created a method to update my Blogger with the Google API (newest version) in C#. I found some solutions, but I have an error while running the app. There is a codeline, that I can't execute. This part of code is in a try {}, but there is no exception message, and the code in catch {} don't run. I can't figure out what's the problem. I have 2 solutions to test, but none of them working for me. Please help me find out whats the problem, I try to solve this for days...
Sorry for my English, I hope You can understand my problem.
Different solutions is marked with #1 and #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;
}
Upvotes: 3
Views: 4199
Reputation: 21
I suppose that you replace the "BLOG_ID" with number strings in following your code, ... Uri blogFeedUri = new Uri("http://www.blogger.com/feeds/" + "BLOG_ID" + "/posts/default");
Right?
Upvotes: 2