Google Blogger API - 无法创建帖子

时间:2013-05-15 15:47:11

标签: asp.net google-api blogger

我正在使用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;
    }

任何帮助都会非常感谢大家......提前感谢;)

2 个答案:

答案 0 :(得分:1)

好的,我是prblm ... 问题在你的博客blogPostUri .. 这应该是。

Uri blogPostUri = new Uri("http://www.blogger.com/feeds/" + blogID + "/posts/default");

答案 1 :(得分:0)

删除该行

newPost.Content.Type = "xhtml";

再次检查...因为您发布的内容类型可能不符合博主政策的标准......这可能有所帮助......