문제

How to get the section's user information (like name, password)? Is there any method that returns it?

I'm trying the function "core_user_get_users_by_field", but it isn't works. That's I've done:

String serverurl = url + "/webservice/rest/server.php" + "?wstoken=" + token + "&wsfunction=" + functionName;

obs: The server was constructed using REST.

도움이 되었습니까?

해결책

This works for me

/webservice/rest/server.php?wstoken=xxx&wsfunction=core_user_get_users_by_field&field=id&values[0]=2

2 is the user id.

You can use any field that uniquely identifies the user. eg: field=username

You can also retrieve more than one user at a time eg: values[0]=2&values[1]=3

This is assuming the function was added as a web service following these instructions

http://docs.moodle.org/25/en/Using_web_services

다른 팁

There is global object called $USER in moodle, this object contains all information about user, So where you want these information just access like,

 global $USER; // <= don't forget to write this before to access
 $USER->username;
 $USER->firstname;
 $USER->lastname;
 $USER->password;

Its works with:

https://url.moodle.xyz/webservice/rest/server.php?wstoken=XXXXXXX&wsfunction=core_user_get_users_by_field&field=id&values%5B0%5D=1306

The query parameters:

  • wsfunction=core_user_get_users_by_field
  • field=id
  • values[0]=1234

values[0] is user id.

To get moodle userdetails based on user name you can use like this :

/webservice/rest/server.php?wstoken=8888&wsfunction=core_user_get_users_by_field&field=username&values[0]=mark

To get JSON data Use :

/webservice/rest/server.php?wstoken=8888&wsfunction=core_user_get_users_by_field&field=username&values[0]=mark&moodlewsrestformat=json

Via curl POST request:

curl \
-X POST \
--data-urlencode "wstoken=123456789..." \
--data-urlencode "wsfunction=core_user_get_users_by_field" \
--data-urlencode "field=id" \
--data-urlencode "values[0]=123456" \
https://moodle.domain.tld/webservice/rest/server.php

As Russell England said:

[...] use any field that uniquely identifies the user. eg: field=username

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top