When posting a node from my slavesite.com site to my hostsite.com site, it keeps giving me the error : "1 1 Invalid API key.." I checked the key I set up on the host site and I gave the key a method access of "node.save". I built a simple module I got from this site(http://thejibe.com/blog/10/8/saving-node-remotely-using-services-and-api-key-authentication) that displays a form that should send the data to the host(server) site. On the server site I have Use Keys checked, Expiry time set to 600, Use sessid unchecked, Apply Content Permissions unchecked. Here is my module code:
<?php
// Define the hostnames that we will be using.
define(SLAVE_HOSTNAME, 'myslavesite.com');
define(HOST_HOSTNAME, 'http://my.hostserver.com');
/*
* Remote call functions so that we can connect to our Host.
* @method - The name of the callmethod to use when retrieving/sending data. ex: "node.save"
*/
function remote_call($method = '') {
// API Key. Replace with your API key created in the previous step.
$api_key = 'a8701f38cca293b29850cae4408fa788';
// Remote services url. Replace example.com with your drupal services site.
$server = HOST_HOSTNAME . '/services/xmlrpc';
// The domain you are sending the request from, which is specified also in the api key.
$domain = SLAVE_HOSTNAME;
// Timestamp for hash
$timestamp = (string) time();
// Single use password
$nonce = user_password();
// Create secure hash using your api key. This will be validated against the Host's.
$hash = hash_hmac('sha256', $timestamp . ';' . $domain . ';' . $nonce . ';' . $method, $api_key);
// Lets format our data in a pretty array() to pass on.
$return = array(
'server' => $server,
'hash' => $hash,
'domain' => $domain,
'timestamp' => $timestamp,
'nonce' => $nonce,
);
return $return;
}
/*
* Remote talking. Formalize our data to send/receive to/from the Host.
* @method - The name of the callmethod to use when retrieving/sending data. ex: "node.save"
* @data - formalized expected data.
*/
function remote_talk($method = '', $data) {
$values = remote_call($method);
// Get a node from the remote server and pass in the required fields see: http://api.drupal.org/api/function/xmlrpc
$xmlrpc_result = xmlrpc($values['server'], $method, $values['hash'], $values['domain'], $values['timestamp'], $values['nonce'], $data);
if ($xmlrpc_result === FALSE) {
return xmlrpc_error();
}
else {
return $xmlrpc_result;
}
}
/*
* Create issue form.
*/
function remote_create_form(&$node, $form_state = '') {
// Title of the new node textfield.
$form['title'] = array(
'#type' => 'textfield',
'#title' => t('Title'),
'#required' => TRUE,
);
// Body of the new node textarea.
$form['body'] = array(
'#type' => 'textarea',
'#title' => t('Description'),
'#rows' => 10,
'#required' => TRUE,
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Submit'),
);
// Submit handler where we will pass on our submitted values to Host.
$form['#submit'][] = 'remote_create_form_submit';
return $form;
}
function remote_create_form_submit($form_values, $form_state) {
// Formalize the node array.
$node['title'] = $form_values['title']['#value']; // These are the values that have been passed on from the form submit.
$node['body'] = $form_values['body']['#value']; // These are the values that have been passed on from the form submit.
$node['type'] = 'page'; // a valid content type on Host.
$node['created'] = time();
$node['status'] = 1;
$node['promote'] = 0;
$node['sticky'] = 0;
$node['format'] = 1;
$node['name'] = 'eric'; // Note: We'll replace this with a valid username that resides on the Host site.
// Create node obj to send through Services.
$node = node_submit($node);
// Send off to our XMLRPC call with the proper call method.
$return = remote_talk('node.save', $node);
// Error reporting.
if($return->is_error) {
drupal_set_message(t('There was an error') . ': ' . t($return->message) . '.', 'error');
} else {
drupal_set_message(t('Thank you for your submission.'));
}
}
thanks