been all through handbooks and lots of code for flex, flash, python, etc.. but can anyone post simple example of remote node save/load using PHP - i.e. one drupal site talking to another.

i have 5.x-1.x-dev

and currently have this:


$domain = 'blogm';
$key = 'dcb265af5b6fceba6aa6704fd99754a8';
$sessid = '8f4bc4f1f5c0f213ef78911d18f0f873';
$timestamp = (string) time();
$nonce = user_password();
$hash = hash_hmac('sha256', $timestamp .';'.$domain .';'. $nonce .';'.'node.load', $key);
$xmlrpc_result = xmlrpc('http://blogs/services/xmlrpc', 'node.load', $hash, $domain, $timestamp, $nonce, 309470);
if ($xmlrpc_result === FALSE) {
print '

' . print_r(xmlrpc_error(), TRUE) . '
';
}
else {
  print '
' . print_r($xmlrpc_result, TRUE) . '
';
}


i have api enabled, sessid disabled

most examples in hbook suggest i need to use sessid and also i need to enable a bunch of user_services perms - but.. none of these exist. Also, for sessid examples they run user.get method; which also doesn't exist.

btw.. my result from above is:

stdClass Object
(
    [is_error] => 1
    [code] => 1
    [message] => Access denied.
)

i am sure i am just missing something small.. no idea why this example isn't in handbook??

Comments

liquidcms’s picture

ok, stumbling around and this seems to work:

this copies node 309473 from blogm site to blogs site.

$server = 'http://blogs/services/xmlrpc';
$domain = 'blogm';
$key = 'dcb265af5b6fceba6aa6704fd99754a8';

$anon_session = xmlrpc($server, 'system.connect');

$timestamp = (string) time();

$nonce = user_password();
$hash = hash_hmac('sha256', $timestamp .';'.$domain .';'. $nonce .';'.'user.login', $key);
$xmlrpc_result = xmlrpc($server, 'user.login', $hash, $domain, $timestamp, $nonce, $anon_session['sessid'], 'myusername', 'mypassword');

if ($xmlrpc_result === FALSE) print '<pre>' . print_r(xmlrpc_error(), TRUE) . '<pre>';
else print '<pre>' . print_r($xmlrpc_result, TRUE) . '<pre>';

$sessid = $xmlrpc_result['sessid'];

$nonce = user_password();
$node = node_load(309473);
unset ($node->nid, $node->vid);
$node->uid = 17;
$hash = hash_hmac('sha256', $timestamp .';'.$domain .';'. $nonce .';'.'node.save', $key);
$xmlrpc_result = xmlrpc($server, 'node.save', $hash, $domain, $timestamp, $nonce, $sessid, $node);

if ($xmlrpc_result === FALSE) print '<pre>' . print_r(xmlrpc_error(), TRUE) . '<pre>';
else print '<pre>' . print_r($xmlrpc_result, TRUE) . '<pre>';

this works for my simple test of copying over a simple (page) node; but is fialing for node types with noderef fields with error: This post can't be referenced. tracking that down next.

skyredwang’s picture

Status: Active » Closed (fixed)