2012-10-15 43 views
20

我正在創建一個可以在wordpress中創建自動帖子的功能。現在,該功能創建了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 }); 

    } 

我的錯誤不是指初始化數組類別。上面的結構不正確,我會從我的代碼中刪除它。

感謝您的關注。

+2

你是否已經有一個字符串數組('字符串[] categories')而不是列表('名單<..>試了一下')? – vstm

+0

我發佈後,我意識到問題是如何處理類別錯誤。我會發布如何解決問題。我很慚愧,因爲之前沒有見過它。你是對的。謝謝你的答案:D – jAbreu

+1

Hi @jAbreu - 你可以發佈你的解決方案,並將其標記爲答案?謝謝! – doublesharp

回答

相關問題