how do I get the user id of a token?

Re: how do I get the user id of a token?

by Purnendu Dash -
Number of replies: 6
Picture of Plugin developers

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: Useful (1)
In reply to Purnendu Dash

Re: how do I get the user id of a token?

by asha chaparala -

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>

In reply to asha chaparala

Re: how do I get the user id of a token?

by Malte Reißig -
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!
In reply to Malte Reißig

Re: how do I get the user id of a token?

by asha chaparala -

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


In reply to asha chaparala

Re: how do I get the user id of a token?

by Malte Reißig -

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!


In reply to Malte Reißig

Re: how do I get the role of user?

by asha chaparala -

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)

In reply to Malte Reißig

Re: how do I get the user id of a token?

by ranu jaiswal -

Hi Malte,

I am new to moodle please suggest me something about core_webservice_get_site_info.

I need to get the logged in user by using this function. when i am using it with admin token it is giving the details of admin but i want to get the logged in user info by using this function how can i do this pls help.

If i create a token for each user and call it by using there token than it will be very time consuming and not right pls suggest asap

Thanx!