需要一个代码示例展示了如何使用后笨WordPress的(Need a code sample sho

2019-08-02 08:30发布

有没有人有一个代码示例,他们可以共享显示了如何使用该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>';
    }
}

Answer 1:

牙齿多咬牙切齿之后,这似乎工作:

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>';
    }
}

最重要的部分是要注意对实际岗位的要素结构。



文章来源: Need a code sample showing how to post to Wordpress using Codeigniter