gpt4 book ai didi

android - 使用 REST Web 服务功能在 Moodle 上上传作业

转载 作者:行者123 更新时间:2023-12-03 20:21:22 27 4
gpt4 key购买 nike

我正在尝试开发 Moodle Android 应用程序。我正在使用 MoodleREST 源代码作为引用。但是这个库不提供上传作业的其余代码。我希望能够通过网络服务调用从移动客户端上传作业。可以使用 WebView 上传作业,但在这种情况下,用户需要再次登录才能访问上传作业页面。

我在这里找到了类似的东西 https://moodle.org/mod/forum/discuss.php?d=207875 .

我是moodle的新手,还在学习它,所以我的问题可能有点天真,所以请多多包涵:)

最佳答案

可以使用 Moodle 网络服务将带有文件的提交上传到作业。

首先使用 core_files_upload 将文件上传到草稿
http://my-moodle-url/moodle/webservice/rest/server.php?wstoken=token_value_xyz&moodlewsrestformat=json&wsfunction=core_files_upload&component=user&filearea=draft&itemid=0&filepath=/&filename=test2.txt&filecontent=TWFuIGlzIGRpc3Rpbmd1aXNoZWQ=&contextlevel=user&instanceid=8
在哪里:
itemid=0 - moodle 将生成并返回 itemid或者你设置 itemid
filecontent - base64 编码的文件内容
instanceid - 用户 ID,其是 Web 服务 token

示例响应:

{
"contextid": 26,
"component": "user",
"filearea": "draft",
"itemid": 293005570,
"filepath": "/",
"filename": "test3.txt",
"url": "http://my-moodle-url/moodle/draftfile.php/26/user/draft/293005570/test3.txt"
}

您可以使用 mod_assign_get_assignments 搜索下一个调用的分配 ID。

然后使用收到的 itemid,这里是“293005570”,在 mod_assign_save_submission http://my-moodle-url/moodle/webservice/rest/server.php?wstoken=token_value_xyz&moodlewsrestformat=json&wsfunction=mod_assign_save_submission&assignmentid=5&plugindata[onlinetext_editor][text]
=some_text_here&plugindata[onlinetext_editor][format]
=1&plugindata[onlinetext_editor][itemid]=521767865&plugindata[files_filemanager]=521767865

这将使用此文件添加作业提交。

我能解决的问题 core_files_uploadmod_assign_save_submission仅对特定用户使用 Web 服务 token ,即每个用户都需要一个可能不实用的 Web 服务 token 。使用网络服务用户 token ,我第一次打电话:
{
"exception": "moodle_exception",
"errorcode": "nofile",
"message": "File not specified"
}

用 postman 测试。这可能是相关的: https://tracker.moodle.org/browse/MDL-61276

关于android - 使用 REST Web 服务功能在 Moodle 上上传作业,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20000660/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com