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其他参数整理如下
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
下次更新发布图片等媒体文件
直接上代码
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_idstring 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
下次更新发布图片等媒体文件
相关文章推荐
- (使用原生Curl发布文章)XML-RPC in WordPress
- (使用Wordpress自带的IXR发布新文章)Using XML-RPC in WordPress
- 終于解決调用wordpress 4.3 xmlrpc api 发布包含分类的文章时返回“抱歉,文章类型不支持您的分类法”错误的問題
- wordpress之客户端发布文章
- SEO优化:WordPress发布文章主动推送到百度,加快收录保护原创
- wordpress文章发布到一定时间后自动关闭评论
- 利用wordpress数据库写API,附加文章redis缓存[菜鸡简单粗暴版]
- wordpress文章自动同步网易博客插件wp2Netease发布
- 使用Word发布文章到 WordPress 博客
- wordpress怎么将文章发布在指定页面?
- 博客工具 - 使用word2007发布文章到wordpress
- iOS 版 MWeb 发布到自建 Wordpress 和 Metaweblog API 使用指南
- 解决wordpress发布文章,图片无法居中的问题
- Jcseg-1.9.7 发布 - Restful API+文章自动摘要/关键字/短语/句子提取
- 黄聪:wordpress文章同步发布到网易、天涯、新浪博客、百度空间插件
- wordpress网站限制发布文章文字数量
- WordPress发布文章前强制要求上传特色图像
- 在WordPress中隐藏文章发布时间
- 用java程序向wordpress发布文章
- WordPress教程:如何在发布文章前对内容进行预处理