0

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

任何帮助将不胜感激人......提前感谢;)

4

2 回答 2

1

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

Uri blogPostUri = new Uri("http://www.blogger.com/feeds/" + blogID + "/posts/default");
于 2013-05-19T12:44:35.857 回答
0

删除线

newPost.Content.Type = "xhtml";

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

于 2013-05-16T13:19:29.903 回答