您的位置:首页 > 编程语言 > C#

C# XML-RPC WordPress API 之发布文章

2018-03-21 13:15 483 查看
引用 CookComputing.XmlRpc
直接上代码
using CookComputing.XmlRpc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class APi
{
/// <summary>
/// 发布新文章
/// </summary>
[XmlRpcMissingMapping(MappingAction.Ignore)]
public struct NewPost
{
public DateTime dateCreated;//发布时间
public string description;//文章正文内容
public string title;//标题
public string[] categories;//分组名称
public string mt_keywords;//Tags,也叫标签
}
public class MetaBlogAPI : XmlRpcClientProtocol
{
/// <summary>
/// 发布新文章
/// </summary>
/// <param name="blogid"></param>
/// <param name="username"></param>
/// <param name="password"></param>
/// <param name="content"></param>
/// <param name="publish"></param>
/// <returns></returns>
[XmlRpcMethod("metaWeblog.newPost")]
public string newPost(string blogid, string username, string password, NewPost content, bool publish)
{
return (string)this.Invoke
("newPost", new object[] { blogid, username, password, content, publish });
}
}
/// <summary>
/// 发布新文章
/// </summary>
/// <param name="Title"></param>
/// <param name="Article"></param>
/// <param name="Tage"></param>
/// <returns></returns>
public static string newPost(string Title, string Article, string Tage, DateTime time)
{
MetaBlogAPI mba = new MetaBlogAPI();
mba.Url = "http://域名.com/xmlrpc.php";
NewPost newpost = new NewPost();
newpost.title = Title;
newpost.dateCreated = time;
newpost.description = Article;
newpost.mt_keywords = Tage;
newpost.categories = new string[] { "分类1" };

return mba.newPost("blog_id", "admin", "admin", newpost, true);
}
}
调用方法
APi.newPost(“标题”, “文章内容”, “TAGE”, 时间);
关于newPost其他参数整理如下

Parameters

int blog_id
string username
string password
struct content string post_type
string post_status
string post_title
int post_author
string post_excerpt
string post_content
datetime post_date_gmt | post_date
string post_format
string post_name: Encoded URL (slug)
string post_password
string comment_status
string ping_status
int sticky
int post_thumbnail
int post_parent
array custom_fields struct string key
string value

struct terms: Taxonomy names as keys, array of term IDs as values.
struct terms_names: Taxonomy names as keys, array of term names as values.
struct enclosure string url
int length
string type

下次更新发布图片等媒体文件
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息