使用 metaWeblog.newPost 向 Drupal 发表 PHPXMLRPC 博客文章:方法参数数量错误

发布于 2024-07-21 18:00:36 字数 1658 浏览 6 评论 0原文

我正在尝试将一个简单的文本字符串发布到我的 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://api.drupal.org/api/function/blogapi_metaweblog_new_post/6

它生成的错误如下:

Server error. Wrong number of method parameters.

有谁知道我做错了什么?

I'm trying to post a simple text string to my drupal site. It needs to be done with metaWeblog.newPost because with blogger.newPost sets all the text as title. I've already tried that one.

I've got this thus far:

 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;

I'm have used this documentation:

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

The error it generates is the following:

Server error. Wrong number of method parameters.

Does anyone know what I'm doing wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

丢了幸福的猪 2024-07-28 18:00:36

解决方案:

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;

Solution:

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;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文