Moodle で次の設定を行いました。
- Web サービスを有効にしました
- REST プロトコルを有効にしました
- 成績というサービスを追加して有効にしました
- 関数 mod_assign_get_grades をサービスに追加しました
- サービスの承認済みユーザーとして webservice ユーザーを割り当てました
- また、残りのプロトコルのユーザーを許可するロールを作成してユーザーに割り当てました
- ユーザーとサービスのトークンも作成しました
以下のコードを使用して API にリクエストを送信しました。
/// SETUP - NEED TO BE CHANGED
$token = '068183c4c700bdcfe2b0bfe24a8043e2';
$domainname = 'http://localhost/Project/moodle';
$functionname = 'mod_assign_get_grades';
// REST RETURNED VALUES FORMAT
$restformat = 'xml'; //Also possible in Moodle 2.2 and later: 'json'
//Setting it to 'json' will fail all calls on earlier Moodle version
/// PARAMETERS - NEED TO BE CHANGED IF YOU CALL A DIFFERENT FUNCTION
$params = array('assignmentids' => array(1));
/// 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);
実行すると、次のエラーが発生します。
No access rights in module context
私が知る限り、適切な機能と権限を割り当てましたが、どこが間違っているのかわかりませんか?