tags:

views:

606

answers:

1

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?

+1  A: 

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;
h3rj4n