Use the metaweblog interface to synchronize Multiple blogs

Source: Internet
Author: User

 

Many people have multiple blogs, and CTRL + C Ctrl + V is not what I am waiting. Synchronizing Multiple blogs makes it easy to use WebService. Although the technology is simple, there is a premise that the blog operator must support it.

With the increasing popularity of XML-RPC, metaweblog has almost become the most popular offline blog sending API, which can be added to any blog through the Standardized WebService interface. Currently, Windows Live writer is popular in offline blog clients published using metaweblog. Here we can find some related setting methods.

Then, how can I use the metaweblog interface to synchronize Multiple blogs? Of course, you can directly create multiple accounts for processing, but it is obviously cumbersome and does not conform to our DIY personality.

Since my personal blog was completely written by myself, I couldn't help but think of writing a metaweblog interface that could connect Windows Live writer to www.dumuzi.cn. Again, the forwarding module was added to it, forward other blogs.

  • Call

Calling metaweblog I used a XML-RPC.NET, an open source. Net Library for processing XML-RPC.

The related calls are very simple, and the corresponding demos can be found online. You only need to implement the API corresponding to metaweblog and blogger in the imetaweblog interface.

Interface

Public interface imetaweblog
{
# Region metaweblog API

[Xmlrpcmethod ("metaweblog. newpost")]
String addpost (string blogid, string username, string password, post, bool publish );

[Xmlrpcmethod ("metaweblog. editpost")]
Bool updatepost (string postid, string username, string password, post, bool publish );

[Xmlrpcmethod ("metaweblog. getpost")]
Post getpost (string postid, string username, string password );

[Xmlrpcmethod ("metaweblog. getcategories")]
Categoryinfo [] getcategories (string blogid, string username, string password );

[Xmlrpcmethod ("metaweblog. getrecentposts")]
Post [] getrecentposts (string blogid, string username, string password, int numberofposts );

[Xmlrpcmethod ("metaweblog. newmediaobject")]
Mediaobjectinfo newmediaobject (string blogid, string username, string password,
Mediaobject );

# Endregion

# Region blogger API

[Xmlrpcmethod ("blogger. deletepost")]
[Return: xmlrpcreturnvalue (description = "returns true.")]
Bool deletepost (string key, string postid, string username, string password, bool publish );

[Xmlrpcmethod ("blogger. getusersblogs")]
Bloginfo [] getusersblogs (string key, string username, string password );

[Xmlrpcmethod ("blogger. getuserinfo")]
Userinfo getuserinfo (string key, string username, string password );

# Endregion
}

You only need to create a class for use. You can use metaweblog to implement the corresponding method of its interface, so that the client can post the blog through access.

Public class metaweblog: xmlrpcservice, imetaweblog
{....}

How to write a blog

String imetaweblog. addpost (string blogid, string username, string password,
Post post, bool publish)
{

If (validateuser (username, password ))
{

.................. Omit n lines to write the content of your blog .....................

Return postid;

}
Else
{
Throw new xmlrpcfaultexception (0, "keyword is not valid! ");
}

}

It is worth noting that, due to the different data structures of various blogs, some interfaces may be confused during calling, for example, string blogid originally refers to the ID of the current user's Multiple blogs returned through getusersblogs, but some blogs return the blog token returned after the blog is sent successfully, that is, postid

The specific analysis may be based on different blogs.

  • Forwarding

It is easier to forward a blog. You only need to define a forwarding interface imetaweblogpost.

Public interface imetaweblogpost: ixmlrpcproxy
{
# Region metaweblog API

[Xmlrpcmethod ("metaweblog. newpost")]
String addpost (string blogid, string username, string password, post, bool publish );

[Xmlrpcmethod ("metaweblog. getcategories")]
Categoryinfo [] getcategories (string blogid, string username, string password );

[Xmlrpcmethod ("metaweblog. newmediaobject")]
Mediaobjectinfo newmediaobject (string blogid, string username, string password,
Mediaobject );

# Endregion

}

The following describes the implementation of the addpost method.

String imetaweblog. addpost (string blogid, string username, string password,
Post post, bool publish)
{

.................. Omit n lines to write the content of your blog .....................

If (true) // determines if Forwarding is required
{

Try
{
Weblogpost. url = "http://www.cnblogs.com/yourname/services/metaweblog.aspx ";
Weblogpost. addpost (blogid, name, password, post, publish );
}
Catch
{
Throw new xmlrpcfaultexception (0, "cnblogs sent failed! ");

}

}

}

Of course, you can define functions such as synchronous deletion and synchronous modification.

 

With the above two steps, we can easily send a blog on www.dumuzi.cn and let it forward other blogs at the same time.

This blog is also published on www.dumuzi.cn www.csdn.net www.cnblogs.com 3blog.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.