遵循各种指南,我成功完成了以下任务:
现在,当我转到内置 Web 服务测试客户端时,选择在 REST API 上使用基于令牌的身份验证,选择“moodle_user_create_users”函数并输入令牌和详细信息,我得到以下结果:
REST protocol: moodle_user_create_users
URL: [...]
'<?xml version="1.0" encoding="UTF-8" ?>
<EXCEPTION class="webservice_access_exception">
<ERRORCODE>accessexception</ERRORCODE>
<MESSAGE>Access control exception</MESSAGE>
<DEBUGINFO>Access to the function moodle_user_create_users() is not allowed.
There could be multiple reasons for this:
1. The service linked to the user token does not contain the function.
2. The service is user-restricted and the user is not listed.
3. The service is IP-restricted and the user IP is not listed.
4. The service is time-restricted and the time has expired.
5. The token is time-restricted and the time has expired.
6. The service requires a specific capability which the user does not have.
7. The function is called with username/password (no user token is sent)
and none of the services has the function to allow the user.
These settings can be found in Administration > Site administration
> Plugins > Web services > External services and Manage tokens.</DEBUGINFO>
</EXCEPTION>
我错过了什么?
我也有同样的例外。然后我在管理仪表板中进行了此更改。
站点管理 -> 移动应用程序 -> 移动设置 -> 为移动设备启用 Web 服务。
打开此功能。
这就是我解决问题的人。
我的答案似乎和其他人经历过的一样:Web 服务测试客户端已经彻底崩溃了。
这是我从事此项目时的一个已知问题,不幸的是,Moodle 决定继续提供此功能。
在可预见的未来,我建议不要浪费时间尝试使用这个“工具”。
在 Moodle 管理仪表板中配置所有元素(功能、用户、角色、操作角色、令牌)...
当我使用Web服务测试客户端选择“core_user_create_users”函数,而不是“moodle_user_create_users”(我忽略为什么使用后者),异常没有出现在我身上,并且响应正常。
// Moodle (4.1) //
我也面临这个错误几天,所以你需要做的是
在请求传递时需要令牌来获取课程详细信息 -> 为此,您的 web_service 需要启用,首先检查您的数据库名称“mdl_externel_sservices”,您可以在其中看到您创建的所有服务,以便获得“ token”首先需要将名为“enabled”的列更改为1,然后只有您才能获取令牌来启用此功能!
站点管理 -> 服务器 -> Web 服务 -> external_services -> 选择您需要访问的服务,然后选中名为“启用”的复选框
现在验证一下数据库是否已更改! 1表示该服务已启用。
现在使用邮递员检查此网址的请求
“http://localhost/moodle/login/token.php?service=test_ws&用户名=ADMIN_NAME&密码=ADMIN_PASS&service=SERVICE_NAME”
它将返回“令牌”
使用此令牌向此网址发出请求 “http://localhost/moodle/webservice/rest/server.php?wstoken=TOKEN&wsfunction=core_course_get_courses(获取课程详细信息)&moodlewsrestformat=json&options[ids][COURSE_ID]=COURSE_ID”
尝试从以下位置启用 Web 服务身份验证: 站点管理 > 插件 > 管理身份验证
尝试获取令牌抛出https://yourmoodle/login/token.php?username=username&password=pass&service=webserviceshortname。 我来自 /admin/settings.php?section=webservicetokens 的令牌也不起作用 并在 /admin/settings.php?section=externalservices
中启用服务功能