作为学生从Moodle API获取信息 [英] Getting information from the Moodle API as a student
问题描述
我目前是一所大学的学生,我每天都在使用Moodle. 我想访问一些可用的信息(例如,我正在上课的信息,应交的作业和时间等)
I'm currently a student at a University and I'm using Moodle everyday. I would like to access some information that is available to me (For example, information of the classes I'm taking, Which assignments are due and when , etc)
我对Moodle的API进行了一些研究,但所有这些似乎都针对实际运行Moodle(我的大学)的高级用户.
I did some research regarding Moodle's API but it all seemed geared toward the power user who actually runs Moodle (My University).
作为学生,我是否有一种简单的方法来获取信息?
Is there an easy way for me as a student to get the information?
我的应用程序使用Node.js
My application uses Node.js
推荐答案
如果您的大学为移动应用程序启用了Web服务,则您可以生成自己的API令牌并调用该移动应用程序所使用的Web服务.如果未启用后者,则必须与管理员联系以获得Web服务访问权限.
If your university has enabled Web Services for the mobile app, you can generate your own API token and call the Web Services used by the mobile app. If the latter are not enabled, you have to get in touch with your administrator to get Web Services access.
使用moodle.org进行演示
首先,让我们获取一个API令牌(用您的密码替换$PASSWORD
):
First, let's get an API token (replace $PASSWORD
with your password):
$ curl -d username="fmcorz" -d password="$PASSWORD" 'https://moodle.org/login/token.php?service=moodle_mobile_app'
{
"token":"SNIPTOKEN",
"privatetoken":"SNIPPRIVATE"
}
接下来,我们需要您的userid
,它将在其他所有Web服务调用中使用.您可以通过调用Web服务core_webservice_get_site_info
获得userid
.确保用上面获得的令牌替换$TOKEN
.
Next, we need your userid
, it will be used throughout other web services call. You can obtain your userid
by calling the web service core_webservice_get_site_info
. Make sure to replace $TOKEN
with the token you obtained above.
$ curl -d wstoken="$TOKEN" -d wsfunction=core_webservice_get_site_info 'https://moodle.org/webservice/rest/server.php?moodlewsrestformat=json' | python -m json.tool | grep userid
"userid": 1451616,
现在您拥有了userid
,我们可以请求您所注册的课程.
Now that you have your userid
, we can request the courses that you are enrolled in.
$ curl -d wstoken="$TOKEN" -d wsfunction=core_enrol_get_users_courses -d userid=1451616 'https://moodle.org/webservice/rest/server.php?moodlewsrestformat=json' | python -m json.tool
[
{
...snip...
"fullname": "Moodle in English",
"id": 5,
...snip...
},
{
...snip...
"fullname": "Moodle en fran\u00e7ais",
"id": 20,
...snip...
},
{
...snip...
"fullname": "Moodle Certification",
"id": 48,
...snip...
}
]
回顾"
先决条件:
- 必须启用移动应用网络服务
- 必须启用 REST 协议
- 您需要一个API令牌
- The Mobile App webservices must be enabled
- The REST protocol must be enabled
- You need an API token
查询:
- 向
YOURHOST/webservice/rest/server.php?moodlewsrestformat=json
发送了请求. - 请求必须是
POST
个请求 - 请求中必须包含
wstoken
:您的令牌 - 请求必须包含
wsfunction
:您正在调用的函数 - 请求类型必须为:
application/x-www-form-urlencoded
- Requests are made to
YOURHOST/webservice/rest/server.php?moodlewsrestformat=json
. - Requests must be
POST
requests - Requests must contain
wstoken
: Your token - Requests must contain
wsfunction
: The function you are calling - Requests type must be:
application/x-www-form-urlencoded
更多
我已经大大简化了它的工作方式和替代方法,但这应该可以帮助您入门.您可能有兴趣查看开发人员文档以获取有关可用Web服务的更多信息:
I've greatly simplified how this works and what alternatives there are, but this should get you started. You will likely be interested in looking at the developer documentation to get more information about the available web services:
- Web服务开发人员文档
- Web服务功能列表(可能不会经常更新)
- Web Services developer documentation
- Web Services functions list (May not be updated frequently)
这篇关于作为学生从Moodle API获取信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!