我正在使用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 = "liz@gmail.com";
createdEntry = service.Insert(blogPostUri, newPost);
}
return createdEntry;
}
任何帮助将是非常感激的家伙....提前感谢;)
好的,这就是问题所在…问题出在你的博客blogPostUri..这应该是。
Uri blogPostUri = new Uri("http://www.blogger.com/feeds/" + blogID + "/posts/default");
删除行
newPost.Content.Type = "xhtml";
然后再检查…因为你发布的内容类型可能不符合博客政策的STNDRDS…