我正在localhost上实现moodle Web服务。 我按照所有步骤注册了服务,并且我有令牌来进行相应的调用。 我已经使用了Jerome Mouneyrac(https://github.com/moodlehq/sample-ws-clients/blob/master/PHP-REST/client.php)的REST PHP模板。
我的代码:
$token = '60d4aef82f787b7a0c8499a648a6a919';
$domainname = 'http://localhost/moodle';
$functionname = 'core_user_create_users';
$restformat = 'json';
$user1 = new stdClass();
$user1->username = 'testo';
$user1->password = 'Password_2015';
$user1->createpassword = 0;
$user1->firstname = 'testfirstname1';
$user1->lastname = 'testlastname1';
$user1->email = 'muletssss@gmail.com';
$user1->auth = 'manual';
$user1->idnumber = '';//'testidnumber1';
$user1->lang = 'es';
$user1->theme = "standard";
$user1->timezone = '-12.5';
$user1->mailformat = 0;
$user1->description = 'Hello World!';
$user1->city = 'testcity1';
$user1->country = 'au';
$users = array($user1);//, $user2);
$params = array('users' => $users);
$serverurl = $domainname . '/webservice/rest/server.php'. '?wstoken=' . $token . '&wsfunction='.$functionname;
require_once('./curl.php');
$curl = new curl;
$restformat = ($restformat == 'json')?'&moodlewsrestformat=' . $restformat:'';
$resp = $curl->post($serverurl . $restformat, $params);
print_r($resp);
如果我执行它,则返回此响应
{"exception":"invalid_parameter_exception","errorcode":"invalidparameter","message":"Detectado valor de par\u00e1metro no v\u00e1lido","debuginfo":"users => Detectado valor de par\u00e1metro no v\u00e1lido: theme => Detectado valor de par\u00e1metro no v\u00e1lido: Invalid external api parameter: the value is \"standard\", the server was expecting \"theme\" type"}
API文档说该值是字符串和标准默认值,因此我对此行进行注释,因为它是可选的。并返回
{"exception":"moodle_exception","errorcode":"forcepasswordchangenotice","message":"error\/forcepasswordchangenotice"}
有谁知道我能做些什么才能正常工作,任何解决方案?
答案 0 :(得分:0)
我遇到了类似的问题,我已经解决了。问题是我在创建Web服务时使用的用户已强制重置密码。创建用户后,我还没有登录,仅将其用于Web服务。因此,我出现了这个错误。我未选中从管理员帐户重置强制密码的问题,此问题已解决。