ワードプレスで自動投稿を作成する機能を作成しています。現在、この機能はワードプレスのブログ投稿を作成しますが、カテゴリに入ることができません。
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 });
}
私の間違いは、配列カテゴリの初期化について言及していませんでした。上記の構造は正しくないため、コードから削除します。
ご清聴ありがとうございました。