【问题标题】:Moodle: get user picture from webserviceMoodle:从网络服务获取用户图片
【发布时间】:2015-05-21 14:59:47
【问题描述】:

通过使用 Moodle Web 服务 (REST) 调用 core_user_get_users_by_field,我成功获取了我的用户详细信息。返回的字段之一是profileimageurl,它链接到我的用户个人资料图片,如下所示:

http://my_moodle_server/pluginfile.php/89/user/icon/f1

不幸的是,该链接仅在我已经登录的浏览器中有效,否则它将重定向到标准用户图标(灰色匿名脸)。

因此,为了从使用 Moodle Web 服务的客户端应用程序中获取实际图片,我想我必须调用 core_files_get_files 并传递正确的值。因此,我尝试将该链接重新映射到调用参数,如下所示:

contextid: 89
component: "user"
filearea: "icon"
itemid: 0
filepath: "/"
filename: "f1.png" (also tryed without .png)
and of course my valid token

但我得到的只是:

{"parents":[],"files":[]}

参数似乎在形式上是正确的(否则我会得到一个异常)但是我只得到空响应,告诉我某些值不正确。

【问题讨论】:

    标签: php web-services moodle


    【解决方案1】:

    好的,我找到了解决问题的方法。我在这里发布答案也是因为没有太多关于 Moodle 网络服务的信息......

    首先,core_files_get_files 不是办法...它只会显示文件信息,不会给你实际的文件内容(二进制)。

    幸运的是,从外部客户端应用程序调用时可以使用等效的 URL:

    http://my_moodle_server/webservice/pluginfile.php

    它接受与http://my_moodle_server/pluginfile.php 相同的参数/格式,此外,您还可以传递您的令牌以进行 Web 服务身份验证。

    所以core_user_get_users_by_field 返回的profileimageurl 字段如下所示:

    http://my_moodle_server/pluginfile.php/89/user/icon/f1
    

    可以变成

    http://my_moodle_server/webservice/pluginfile.php/89/user/icon/f1?token=my_web_service_token
    

    还要注意附加?token=参数是必需的

    【讨论】:

    • 我在获取 Myrpivate 文件列表时遇到了同样的问题,如何从 webservice 部分获取它们这是我制作的 URL webservice/rest/server.php?wstoken=3afe18c8697dac9518d59bb8f10429b4&wsfunction=core_files_get_files&moodlewsrestformat=json&contextid=2&component =&filearea=&itemid=0&filepath=
    • 在 admin/webservice/service.php?id=2 页面,我们启用下载。这解决了我们的问题
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-08
    • 1970-01-01
    • 2013-07-18
    • 1970-01-01
    • 2021-09-23
    相关资源
    最近更新 更多