【问题标题】:Google Blogger API - cannot create a postGoogle Blogger API - 无法创建帖子
【发布时间】:2013-05-19 20:44:35
【问题描述】:

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

任何帮助都将不胜感激......在此先感谢;)

【问题讨论】:

    标签: asp.net google-api blogger


    【解决方案1】:

    好的,我知道问题... 问题出在你的博客 blogPostUri.. 应该是这样的。

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

    【讨论】:

    • user2374372...我爱你 :) 试过了,效果很好,谢谢一百万!
    【解决方案2】:

    删除线

    newPost.Content.Type = "xhtml";
    

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

    【讨论】:

      猜你喜欢
      • 2023-04-09
      • 1970-01-01
      • 2014-06-25
      • 1970-01-01
      • 2021-11-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多