首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用metaWeblog.newPost写给Drupal的博客文章:错误的方法参数数量

用metaWeblog.newPost写给Drupal的博客文章:错误的方法参数数量
EN

Stack Overflow用户
提问于 2009-05-28 14:44:12
回答 1查看 1.3K关注 0票数 1

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

到目前为止,我得到了这样的结论:

代码语言:javascript
复制
 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

它产生的错误如下:

代码语言:javascript
复制
Server error. Wrong number of method parameters.

有人知道我做错了什么吗?

EN

回答 1

Stack Overflow用户

发布于 2009-06-01 16:49:38

解决方案:

代码语言:javascript
复制
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;
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/921214

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档