tohokuaikiのチラシの裏

技術的ネタとか。

WordPressのXMLRPCで、expat reports error code 5 とか出るので困った

こんなエラーね。

expat reports error code 5
description: Invalid document end
line: 1
column: 1
byte index: 0
total bytes: 0

data beginning 0 before byte index: 1

相当悩んだ。dateCreatedをObjectで与えないとダメだったみたい。

<?php
// create post
$date = new stdClass();
$date->scalar = strftime("%FT%R:%S", time() - 100000);
$date->xmlrpc_type = 'datetime';
$date->timestamp = time(); 

$content = array(
    'wp_slug' => WP_PAGE_SLUG,
    'wp_password' => "",
    'wp_author_id' => 1,
    'title' => WP_PAGE_SLUG,
    'description' => $html,
    'mt_excerpt' => $html,
    'wp_page_order' => 0,
    'wp_page_parent_id' => 0,
    'mt_allow_comments' => 0,
    'mt_allow_pings' => 0,
    'dateCreated' => $date,);
$page = $xmlrpc->newPage(WP_BLOGID, WP_USER, WP_PASS, $content ,  1);

こんな感じ。stdClassをnewしたのなんて初めて。