我正在创建一个在 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;
}
我尝试先上课并仅传递类别名称以避免错误:
var wordpress = XmlRpcProxyGen.Create<IWordpress>();
Category[] categories= wordpress.getCategories(0, username, password);
构建帖子类别的方法作为参数接收。此方法属于 Post 类。该类别以这种方式插入帖子中:
Categories.Add(category.categoryName);
有人可以帮我吗?我已经多次看到这段代码,以至于我看不出哪里出错了:(。
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;
}
并初始化属性:
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 });
}
我的错误不是指初始化数组类别。上面的结构不正确,我将从我的代码中删除它。
感谢您的关注。