Hi,
Following on from this issue:
http://drupal.org/node/305011#comment-1019188
I've tried really hard to reverse engineer the API keys for Services module, cos the documentation seems to be waaay out of date, and it just is not working.
It seems to me API keys are not working at all right now. They don't even seem to be used by node.get and views.get methods at all. I have generated an API key using the Services Keys admin page (at admin/build/services/keys).
My PHP (or what matters, at any rate) looks like this:
session_start();
function getUniqueCode($length = "") {
$code = md5(uniqid(rand(), true));
if ($length != "") return substr($code, 0, $length);
else return $code;
}
$timestamp = (string) strtotime("now");
$domain = 'defaqto.com';
//this is the array key, generated for domain 'localhost'
$kid = '34f37fc6819763d326b55e55b330138f';
$nonce = getUniqueCode("10");
$method_name = 'file.getNodeFiles';
$hash_parameters = array(
$timestamp,
$domain,
$nonce,
$method_name,
);
$hash = hash_hmac("sha256", implode(';', $hash_parameters), $kid);
$request = xmlrpc_encode_request(
$method_name, array(
$hash,
$domain,
$timestamp,
$nonce,
session_id(),
19,
)
);
$context = stream_context_create(
array(
'http' => array(
'method' => "POST",
'header' => "Content-Type: text/xml",
'content' => $request
)
)
);
print '<h1>Sent</h1><pre>'. htmlspecialchars(print_r($request, true)) .'</pre>';
$file = file_get_contents("http://cms.defaqto.com/services/xmlrpc", false, $context);
$response = xmlrpc_decode($file);
if (xmlrpc_is_fault($response)) {
trigger_error("xmlrpc: $response[faultString] ($response[faultCode])");
} else {
print '<h1>Received</h1><pre>'. htmlspecialchars(print_r($response, true)) .'</pre>';
}
If I do this in the Service Browser I always get "Invalid API key" and if I do it in my test script I get absolutely nothing. =(
I really need to get this resolved. Can anyone help me? Without API keys the Services module is useless and I can't work out if it's something I'm doing or the module is broken. If I can't get it working soon I'll be forced to revert to a previous version that worked.
Comments
Comment #1
greg.harveyBTW, $domain is set to 'localhost' in my script - which is what was entered when the key was created. So that's not the issue.
Comment #2
ethank commentedAPI keys are actually working, we have the current version of services deployed in production with both a Flex app and websites, using XMl-RPC.
We have written signing code in Python, AS3, .NET and PHP
Comment #3
greg.harveyWeird - hopefully someone can tell me why the above is broken then, because I really can't see what I'm doing wrong. I'll try and uninstall and fresh install now. Perhaps something broke in the upgrade from 0.9 to 0.13?
Also, on my installation views.get and node.get do not allow the use of API keys, even though they are enabled. Weird!! =(
Comment #4
greg.harveySwitching to support request, since other users have no problem.
Comment #5
greg.harveyAlright! Fresh install did the trick! =)
That was driving me mad... thanks for letting me know it works for you, ethank - allowed me to continue trying stuff in the confidence it *should* work!
Comment #6
greg.harveyComment #7
greg.harvey