PHPXMLRPC博客使用metaWeblog.newPost发布到Drupal:方法参数数量错误

时间:2009-05-28 14:44:12

标签: php xml-rpc

我正在尝试将一个简单的文本字符串发布到我的drupal站点。它需要使用metaWeblog.newPost完成,因为blogger.newPost将所有文本设置为标题。我已经尝过那个了。

到目前为止我已经得到了这个:

 require_once('xmlrpc-v1.174.inc');

$appkey     = "0001000";
$blogid     = "blog";

$username   = "xxxx";
$password   = "xxxx";
$text       = "testing";
$boolean    = "true";

$content['title'] = "Testen van metaWeblog.newPost";
$content['description'] = $text;

$oMessage = new xmlrpcmsg('metaWeblog.newPost');

$oMessage->addParam( new xmlrpcval( $blogid , 'string' ));
$oMessage->addParam( new xmlrpcval( $username , 'string' ));
$oMessage->addParam( new xmlrpcval( $password , 'string' ));
$oMessage->addParam( $content , 'struct' );
$oMessage->addParam( new xmlrpcval( $boolean , 'boolean' ));

$oClient = new xmlrpc_client("http://example.nl/drupal/xmlrpc.php");

$oClient->setDebug(0);

$oResponse = $oClient->send( $oMessage );

if ($oResponse->faultCode() ) {
    $xWebserviceOutput = $oResponse->faultString();
}
else
{
    $oValue = $oResponse->value();
    $xWebserviceOutput = $oValue->scalarval();
}

echo $xWebserviceOutput;

我已经使用过这个文档:

http://www.sixapart.com/developers/xmlrpc/metaweblog_api/metaweblognewpost.html http://expressionengine.com/wiki/How_to_add_an_entry_using_PHP_and_Metaweblog_API/ http://api.drupal.org/api/function/blogapi_metaweblog_new_post/6

它产生的错误如下:

Server error. Wrong number of method parameters.

有谁知道我做错了什么?

1 个答案:

答案 0 :(得分:1)

解决方案:

require_once('xmlrpc-v1.174.inc');

$client = new xmlrpc_client( "http://example.nl/drupal/xmlrpc.php" );
$f = new xmlrpcmsg("metaWeblog.newPost",
    array(
        new xmlrpcval( "blog", "string"), // BlogID (Ignored)
        new xmlrpcval( "xxxx", "string"), // User
        new xmlrpcval( "xxxx", "string"),    // Pass
        new xmlrpcval( // body
        array(
            "title" => new xmlrpcval("Testen van metaWeblog", "string"),

        ), "struct"),
        new xmlrpcval(true, "boolean") // publish
    )
);

$oResponse = $client->send($f);


for ($i = 0; $i < $f->getNumParams(); $i++) {
    $e = $f->getParam($i);
    echo $e->scalarval();
}

$xWebserviceOutput;

if ($oResponse->faultCode() ) {
    $xWebserviceOutput = $oResponse->faultString();
}
else
{
    $oValue = $oResponse->value();
    $xWebserviceOutput = $oValue->scalarval();
}

echo $xWebserviceOutput;