需要一个代码示例,演示如何使用Codeigniter发布到Wordpress

时间:2009-08-24 19:48:18

标签: wordpress codeigniter xml-rpc

有没有人有他们可以分享的代码示例,展示了如何使用CodeIgniter xml-rpc库向Wordpress发布基本博客文章?

到目前为止,我有这个,它总是会导致“登录/传递组合不良”,尽管我使用了正确的组合。

function doPost(){

    $this->load->library('xmlrpc');

    $bloguser = "theUserid";
    $blogpass = "thePassword";
    $blogid = 0; //I've tried 0 and 1 here. 
    $post['title'] = "The title of a new post";
    $post['description'] = "The body of the post.";
    $this->xmlrpc->server("http://localhost/blog/xmlrpc.php", 80);
    $this->xmlrpc->method('metaWeblog.newPost');

    $this->xmlrpc->request = array($blogid, $bloguser, $blogpass, $post, TRUE);
    if ( ! $this->xmlrpc->send_request())
    {
        echo $this->xmlrpc->display_error();
    }
    else
    {
        echo '<pre>';
        print_r($this->xmlrpc->display_response());
        echo '</pre>';
    }
}

1 个答案:

答案 0 :(得分:3)

咬牙切齿之后,这似乎有效:

function doPost(){

    $this->load->library('xmlrpc');

    $bloguser = "theUserID";
    $blogpass = "thePassword";
    $blogid = 1; 
    $publishImmediately = TRUE;

    $thePost = array(array('title'  => array('this is the title','string'),
                            'description'    => array('this is the description','string')
                            ),
                     'struct');               


    $myPost = "my post";
    //$this->xmlrpc->set_debug(TRUE);
    $this->xmlrpc->server("http://url.to/xmlrpc.php", 80);
    $this->xmlrpc->method('metaWeblog.newPost');

    $request = array($blogid, $bloguser, $blogpass, $thePost, $publishImmediately);

    $this->xmlrpc->request($request);
    $result = $this->xmlrpc->send_request();

    if ( !$result )
    {
        echo $this->xmlrpc->display_error();
    }
    else
    {
        echo '<pre>';
        print_r($this->xmlrpc->display_response());
        echo '</pre>';
    }
}

重要的是要注意实际帖子元素的结构。