【发布时间】:2012-10-04 23:26:33
【问题描述】:
我正在创建一个在 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 });
}
我的错误不是指初始化数组类别。上面的结构不正确,我将从我的代码中删除它。
感谢您的关注。
【问题讨论】:
-
您是否已经尝试过使用字符串数组 (
string[] categories) 而不是列表 (List<..>)? -
我在发布问题后意识到处理类别有多么错误。我将发布如何解决问题。我为以前没有见过它而感到羞耻。你说得对。感谢您的回答:D
-
嗨@jAbreu - 你能发布你的解决方案并将其标记为答案吗?谢谢!
-
示例代码无效,使用正确的类别。
标签: c# wordpress xml-rpc metaweblog