我已经有来自注释表的样本注释。我想使用moodle Web服务显示评论数据,但是错误参数总是会出现。
这是评论表中评论的示例 enter image description here 使用的穆迪版本为3.7
<?php
//===========================================================
// Web services's Token for connecting to moodle
$token = 'xxxxxx';
$domainname = 'http://localhost/moodle';
$functionname = 'core_comment_get_comments';
//===========================================================
$contextlevel1 = new stdClass();
$contextlevel1 = 'Context_user';
$contextlevel = array($contextlevel1);
$instanceid1 = new stdClass();
$instanceid1 = 2;
$instanceid = array($instanceid1);
$component1 = new stdClass();
$component1 = 'blog';
$component = array($component1);
$itemid1 = new stdClass();
$itemid1 = 1;
$itemid = array($itemid1);
$params = array('contextlevel' => $contextlevel,'instanceid'=>$instanceid,'component'=>$component,'itemid'=>$itemid);
$restformat = 'xml';
/// REST CALL
header('Content-Type: text/plain');
$serverurl = $domainname . '/webservice/rest/server.php'. '?wstoken=' . $token . '&wsfunction='.$functionname;
require_once('./curl.php');
$curl = new curl;
//if rest format == 'xml', then we do not add the param for backward compatibility with Moodle < 2.2
$restformat = ($restformat == 'json')?'&moodlewsrestformat=' . $restformat:'';
$resp = $curl->post($serverurl . $restformat, $params);
print_r($resp);
//$json_data = json_encode($resp,JSON_PRETTY_PRINT);
file_put_contents('courses.json', $resp);
echo '</br>';
echo '</br>';
echo "Operation done successfully\n";
?>
我期望的结果是评论表中的“测试博客测试”评论