问题
I searched, could not find a correct way to create new users on owncloud server. I tried to apply what User Provisioning API says, but I always get this response:
<ocs>
<meta>
<status>failed</status>
<statuscode>999</statuscode>
<message>Invalid query, please check the syntax. API specifications are here: http://www.freedesktop.org/wiki/Specifications/open-collaboration-services. DEBUG OUTPUT: debug output: http request method: POST http request uri: /owncloud/ocs/v1.php/cloud/users%20-d%20userid=%22Frank%22%20-d%20password=%22frankspassword%22</message>
</meta>
</ocs>
My HTTP POST is:
http://myuser:mypassword@ip_owncloud_server/owncloud/ocs/v1.php/cloud/users -d userid="Frank" -d password="frankspassword"
What is wrong here?
回答1:
first, the example given in the OwnCloud documentation is not complete. It assumes you're using curl or other command line utility. I got this script to work using jQuery AJAX:
<script>
function doMake() {
$.ajax({
type: 'POST',
url: 'http://myowncloud.local:8080/ocs/v1.php/cloud/users',
data: {'userid':'test', 'password':'test'},
crossDomain: true,
beforeSend: function(xhr) {
xhr.setRequestHeader('Authorization', 'Basic ' + window.btoa(unescape(encodeURIComponent('owncloud-dev' + ':' + 'password'))))
}
}).done( function(data, status, xhr) {
document.write(status);
}).fail( function(xhr, status, error) {
document.write(status + ":" + error);
});
}
</script>
save the above as adduser.html in your root of your owncloud installed directory. replace the admin username/password in the Authorization requestHeader.
回答2:
From the message it looks like it's complaining about having quotes in your userid (and maybe password). I know you took that from the example, but if you remove the quotes it will probably have a better chance of working:
http://myuser:mypassword@ip_owncloud_server/owncloud/ocs/v1.php/cloud/users -d userid=Frank -d password=frankspassword
If you want to quote things to be protected from the shell, put the quotes around the whole argument like
http://myuser:mypassword@ip_owncloud_server/owncloud/ocs/v1.php/cloud/users -d "userid=Frank" -d "password=frankspassword"
回答3:
Hi i am posting here an answer found here for anyone who would pass by this thread: I found this searching for a similar solution my self on the Owncloud deve mailinglist : http://owncloud.10557.n7.nabble.com/User-Provisioning-API-PHP-Authentification-Error-td15927.html
It appears that using this in php w/ cURL:
<?php
$username = 'lukas';
$password = 'lukas';
$ch = curl_init('http://localhost/master/ocs/v1.php/cloud/groups');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
$output = curl_exec($ch);
curl_close($ch);
echo $output;
Hope it helps
来源:https://stackoverflow.com/questions/30536827/create-user-on-owncloud