如何通过在C#谷歌API发布到Blogger [英] How to post to Blogger via Google API in C#

查看:196
本文介绍了如何通过在C#谷歌API发布到Blogger的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了C#中的谷歌API(最新版本)来更新我的Blogger的方法。我找到了一些解决方案,但在运行应用程序,我有一个错误。有一个$ C $克莱因,我不能执行。 code的这一部分是在一个try {},但没有异常消息,并在渔获code {}不运行。我想不出有什么问题。我有2个解决方案进行测试,但他们没有为我工作。请帮我找出什么问题,我试图解决这个天...

对不起,我的英语,我希望你能理解我的问题。

不同的解决方案都标有#1和#2。

 公共静态布尔AddPost(字符串名称,字符串bodyHTML,字符串[]标签,用户名字符串,字符串密码,串blogurl)
    {
        Service服务=新的服务(博客,更新);
        service.Credentials =新GDataCredentials(用户名,密码);
        AtomEntry newPost =新AtomEntry();
        newPost.Title.Text =称号;
        newPost.Content =新AtomContent();
        newPost.Content.Content = bodyHTML;
        newPost.Content.Type =HTML;
        的foreach(在标签字符串标签)
        {
            AtomCategory猫=新AtomCategory();
            cat.Scheme =新的URI(http://www.blogger.com/atom/ns#);
            cat.Term =标签;
            newPost.Categories.Add(猫);
        }
        AtomEntry响应=无效;
        尝试
        {
            #1 ------------------------------------------------ ------
            乌里blogFeedUri =新的URI(http://www.blogger.com/feeds/+BLOG_ID+/职位/默认);
            响应= service.Insert(blogFeedUri,newPost);            #2 ------------------------------------------------ ------
            响应= service.Insert(新的URI(blogurl +供稿/职位/默认),newPost);
        }
        赶上(GDataRequestException除外)
        {
            如果(exception.ResponseString ==博客已经超过了速率限制或以其他方式需要新帖字的验证)
            {
                返回false;
            }
            其他
            {
                抛出异常;
            }
        }
        如果(响应== NULL)
        {
            抛出新的异常(出事了);
        }
        返回true;
    }


解决方案

我想你用数字串代替BLOG_ID,在下面的code,
...
            乌里blogFeedUri =新的URI(http://www.blogger.com/feeds/+BLOG_ID+/职位/默认);

右键?

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;
    }

解决方案

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?

这篇关于如何通过在C#谷歌API发布到Blogger的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆