Web services

how do I get the user id of a token?

 
 
Picture of dang quang
how do I get the user id of a token?
 

Hi everyone. I am beginner, my problem is how to get the information of a user when he login into mobile app. the infomation includes courses which he enrol, his profile... I think to get the information I need to know his Id. but when he login, I just get his token by using API function. so how to get the user Id by user token? or is there any way to get the information of user without id?

please help me! thank so much!

 
Average of ratings: -
Picture of Dual Cube
Re: how do I get the user id of a token?
 

Dear Dang,

Hope you are doing good. I understand you are a beginner, and there is no end to the number of problems you may have to face in the initial stages of getting acquainted with Moodle. Don’t worry you will get a hang of it in sometime.

Dang, may I know what exactly you mean by "mobile app"?

To get the details of a logged in user, use the global variable $USER. Define global $USER; in the page where you want to get the user details and then view the full user details by print_r($USER);

To get the user id, you may do this,

$userId = $USER->id;

Do let me know if this helps.

All the best!  Would love to hear from you again.

Purnendu (developer)

DualCube

 
Average of ratings: -
Picture of asha chaparala
Re: how do I get the user id of a token?
 

Hi,

i am developing one app,i want moodle users also can use my app,i want to access all his courses,profile details and all data related to that user to show in my app(how can i achieve this from java code).i am getting the below exception when i request this api.please tell me how to fix this issue

url:http://school.demo.moodle.net/webservice/rest/server.php?wstoken=cd72aa99e236fd9c760d617d69b6bcb0&wsfunction=core_user_get_users_by_field

<?xml version="1.0" encoding="UTF-8" ?>
<EXCEPTION class="webservice_access_exception">
    <ERRORCODE>accessexception</ERRORCODE>
    <MESSAGE>Access control exception</MESSAGE>
</EXCEPTION>

 
Average of ratings: -
Picture of Malte Reißig
Re: how do I get the user id of a token?
 
Hi i!

- Add the "core_webservice_get_site_info" function call to your "External Service"-Configuration
- Ask the "core_webservice_get_site_info" with a wstoken and the response will get you the 'userid' (among other infos) related to this wstoken.

And depending on the function and your "webservice authenticaton method" configuration:
- Double check if the "User" (related to the "wstoken" you're talking to the moodle-webservice with) has the necessary "Capability" or "Role" active (set to 'true') to actually call the function.

Cheers & Have Fun!
 
Average of ratings: -
Picture of asha chaparala
Re: how do I get the user id of a token?
 

HI,

Thankyou very much for your reply,i would like to know how can i add more function to external servise already created with out creating custom servise.


i cant see this option Settings > Site administration > Plugins > Web services > Manage services >Edit

(please let me know the reason)

I am using below login credentials(test account)

username:admin

password:sandbox


 
Average of ratings: -
Picture of Malte Reißig
Re: how do I get the user id of a token?
 

Hi, no problem, yesterday I just had some spare minutes to spent on this. 


But sorry, sure I don't know the reasons why you can not "Manage Services" as an "admin", have you checked if the webservice plugin is active?

- Any webservice should have a defined number of webservice functions and this should be created as an external service configuration ("custom service" you say) as far as i know

- Try to be explicit when asking for help (add the urls to the docs you and webpages you were looking at while trying to solve your issue, this may help other potential supporters here in this forum)

- I dont have access to any moodle with administratior-priviliges right now, so I cannot investigate your issue.


Let me ask, what is it for an app you want to build and why?

All the best & Cheers!


 
Average of ratings: -
Picture of asha chaparala
Re: how do I get the role of user?
 

hi sir,

thankyou i fixed that issue problem is webservises is not enabled.

i developed one app,i want to allow moodle users also can use it.

i have one doubt how to get role of the user for that site not for single course.

For example:for site admin(get role as adimin)

 
Average of ratings: -