无法使用 Web 服务将角色分配给用户
Cannot assign role to user using web service
我正在尝试使用网络服务分配角色。我已尝试使用以下代码来分配角色。
$user_id= 35;
$context_id=1;
$role_id=5;
$assignment = array( 'roleid' => $role_id, 'userid' => $user_id, 'contextid' => $context_id );
$assignments = array( $assignment );
$params = array( 'assignments' => $assignments );
$functionname = 'core_role_assign_roles';
$serverurl = $domainname . '/webservice/rest/server.php'. '?wstoken=' . $token . '&wsfunction='.$functionname;
$response = $curl->post( $serverurl . $restformat, $params );
print_r( $response );
当我 运行 代码时,我得到以下响应。请帮忙
{"exception":"invalid_parameter_exception","errorcode":"invalidparameter","message":"Invalid parameter value detected","debuginfo":"Can not assign roleid=5 in contextid=1"}
在我将角色添加到编辑角色页面的 'Allow role assignments' 选项后,它起作用了。
我正在尝试使用网络服务分配角色。我已尝试使用以下代码来分配角色。
$user_id= 35;
$context_id=1;
$role_id=5;
$assignment = array( 'roleid' => $role_id, 'userid' => $user_id, 'contextid' => $context_id );
$assignments = array( $assignment );
$params = array( 'assignments' => $assignments );
$functionname = 'core_role_assign_roles';
$serverurl = $domainname . '/webservice/rest/server.php'. '?wstoken=' . $token . '&wsfunction='.$functionname;
$response = $curl->post( $serverurl . $restformat, $params );
print_r( $response );
当我 运行 代码时,我得到以下响应。请帮忙
{"exception":"invalid_parameter_exception","errorcode":"invalidparameter","message":"Invalid parameter value detected","debuginfo":"Can not assign roleid=5 in contextid=1"}
在我将角色添加到编辑角色页面的 'Allow role assignments' 选项后,它起作用了。