jAb*_*reu 21 c# wordpress xml-rpc metaweblog
我正在创建一个在wordpress中创建自动帖子的功能.现在,该功能创建了wordpress博客帖子,但我无法输入该类别.
public class Post
{
public string Title { get; set; }
public string Description { get; set; }
public string PostType { get; set; }
public DateTime DateCreated { get; set; }
public DateTime DateCreatedGmt { get; set; }
public List<string> Categories { get; set; }
public List<string> MtKeywords { get; set; }
public string MtExcerpt { get; set; }
public string MtTextMore { get; set; }
public string MtAllowComments { get; set; }
public string MtAllowPings { get; set; }
public string WpSlug { get; set; }
public string WpPassord { get; set; }
public string WpAuthorId { get; set; }
public string WpAuthorDisplayName { get; set; }
public string PostStatus { get; set; }
public string WpPostFormat { get; set; }
public bool Sticky { get; set; }
public List<CustomFields> CustomFields;
public Enclosure Enclosure;
}
Run Code Online (Sandbox Code Playgroud)
我试着先上课,只传递类别名称以避免错误:
var wordpress = XmlRpcProxyGen.Create<IWordpress>();
Category[] categories= wordpress.getCategories(0, username, password);
Run Code Online (Sandbox Code Playgroud)
构建帖子类别的方法作为参数接收.此方法属于Post类.该类别以这种方式插入帖子中:
Categories.Add(category.categoryName);
Run Code Online (Sandbox Code Playgroud)
谁能帮助我?我已经看过很多次这段代码,我看不出哪里出错了:(.
Post的属性在文档中获得:http://codex.wordpress.org/XML-RPC_MetaWeblog_API#metaWeblog.newPost.我正在使用CookComputing.XmlRpc - http://xml-rpc.net/ - 版本2.5.0
在我发布问题后我意识到处理类别有多么错误.
要发布帖子,我们创建:
class MetaWeblogClient : XmlRpcClientProtocol
{
[XmlRpcMissingMapping(MappingAction.Ignore)]
public struct Post
{
public DateTime dateCreated;
public string description;
public string title;
public string[] categories;
public string permalink;
public string postid;
public string userid;
public string wp_slug;
}
Run Code Online (Sandbox Code Playgroud)
并初始化以下属性:
public void newPost(string userid, string password, string description, string title)
{
this.Url = "http://#########.wordpress.com/xmlrpc.php";
Post post = new Post();
post.categories = new string[1];
post.categories[0] = "Category Name";
post.dateCreated = DateTime.Now;
post.userid = userid;
post.description = description;
post.title = title;
newPost("0", userid, password, post, true);
}
[XmlRpcMethod("metaWeblog.newPost")]
public string newPost(string blogid, string authorId, string password, MetaWeblogClient.Post string description, bool publish)
{
//return string postid
return returnPostId = (string)this.Invoke("newPost", new Object[] { blogid, authorId, password, description, publish });
}
Run Code Online (Sandbox Code Playgroud)
我的错误并不是指初始化数组类别.上面的结构不正确,我将从我的代码中删除它.
感谢您的关注.
您可以使用的另一件事是 wp.newPost 方法:
http://codex.wordpress.org/XML-RPC_WordPress_API/Posts#wp.newPost
这使用“分类法”而不是类别。
我目前正在更新 JoeBlogs Wordpress 包装器以支持分类法(类别)
https://github.com/alexjamesbrown/joeblogs
| 归档时间: |
|
| 查看次数: |
2429 次 |
| 最近记录: |