我在 1 个 drupal 站点上有一段代码,用于在多站点设置中创建另一个 drupal 站点的节点。看起来我得到了 sessionid 并且登录得很好,但是在尝试创建“页面”节点时,我得到“访问被拒绝”。在服务-> 设置下,我有“密钥验证”,“使用密钥”未选中,“使用 sessid”已选中。我为登录用户提供了agev 权限:“创建页面内容”、“管理服务”等......下面是我的代码:
<p>Test Page 1</p>
<? $url = 'http://drupal2.dev/xmlrpc.php'; ?>
<?
$conn = xmlrpc($url, 'system.connect');
print_r($conn);
?>
<p>--</p>
<?
$login = xmlrpc($url, 'user.login', $conn['sessid'], 'superuser_name', 'superuser_password');
print_r($login);
?>
<p>--</p>
<?
$data=array('type'=>'page', 'title'=>'Test', 'body'=>'test');
$data_s=serialize($data);
$result = xmlrpc($url, 'node.save', $login['sessid'], $data_s);
echo $result;
//echo $data_s;
?>
<?
if($error = xmlrpc_error()){
if($error->code > 0){
$error->message = t('Outgoing HTTP request failed because the socket could not be opened.');
}
drupal_set_message(t('Operation failed because the remote site gave an error: %message (@code).',
array(
'%message' => $error->message,
'@code' => $error->code
)
)
);
}
?>
这个脚本的输出是:
Array ( [sessid] => 9eebdde9bf0bfd9610cc2f03af131a9c [user] => Array ( [uid] => 0 [hostname] => ::1 [roles] => Array ( [1] => anonymous user ) [session] => [cache] => 0 ) )
--
Array ( [sessid] => c0ca4c599e41e97e7a7ceb43ee43249e [user] => Array ( [uid] => 1 [name] => eric [pass] => 13583b155536098b98df41bb69fcc53 [mail] => email@gmail.com [mode] => 0 [sort] => 0 [threshold] => 0 [theme] => [signature] => [signature_format] => 0 [created] => 1271813934 [access] => 1275867734 [login] => 1275868794 [status] => 1 [timezone] => [language] => [picture] => [init] => email@gmail.com [data] => a:0:{} [roles] => Array ( [2] => authenticated user ) ) )
--