【问题标题】:Sending data to Firebase from Matlab从 Matlab 向 Firebase 发送数据
【发布时间】:2019-09-21 15:02:09
【问题描述】:

我想从 Matlab 将数据保存到 firebase。 firebase 是否有类似 ThingSpeak 之类的 api 调用?如何通过 API 调用从 matlab 发送 JSON 数据?

我正在从 Matlab 进行 API 调用,例如 JSON:

    Firebase_Url = 'https://ecgproject-86945.firebaseio.com/';
    writeApiKey = '***';
    data = ['api_key=',writeApiKey,'&name=',"JSOpn9ZC54A4P4RoqVa"];
    response = webwrite(Firebase_Url,data) 

    %data = struct('api_key',writeApiKey,'field1',data); //also tries this
    %options = weboptions('MediaType','application/json'); 

错误:

Error using readContentFromWebService (line 46)
The server returned the status 405 with message "Method Not Allowed" in response to the
request to URL https://ecgproject-86945.firebaseio.com/.

Error in webwrite (line 139)
    [varargout{1:nargout}] = readContentFromWebService(connection, options);

Error in Untitled (line 16)
response = webwrite(Firebase_Url,data)

【问题讨论】:

  • 我昨天回答了一个非常相似的问题:stackoverflow.com/questions/53467712/…
  • 是,但没有指定如何使用 Matlab 中的 Rest 服务。
  • 我对“从 Matlab 执行 HTTP 调用”进行了快速搜索,看到了很多有希望的结果。你有没有尝试过这些?你在哪里卡住了?
  • 我以前用过 Thingspeak。我按照 matlab 的 webwrite() 的教程进行操作。但我猜firebase对数据有不同的格式。这是链接:mathworks.com/help/matlab/ref/webwrite.html。我还用我现在在 matlab 上为 firebase 运行的代码更新了我的问题。
  • 如果您尝试过某事,请编辑您的问题以包含您尝试过的内容(您刚刚看到的内容)。从错误消息看来,您没有传递请求正文,这是执行 HTTP POST 请求时所必需的。您是否尝试过 mathworks.com/help/matlab/ref/webwrite.html 中的“写入 JSON 对象”示例?

标签: matlab rest firebase


【解决方案1】:

从阅读mathworks documentation on webwrite你需要使用双参数版本的方法,在第二个data对象里面传入附加信息:

data = ['api_key=',writeApiKey,'&name=',"JSOpn9ZC54A4P4RoqVa"];

response = webwrite(FirebaseURL,data)

【讨论】:

  • 这也行不通。我也为这种方法编辑了我的问题。我认为 firebase API 有不同的格式。您是否使用过 matlab 的 firebase api?谢谢
【解决方案2】:

好的,我找到了解决方案,显然我没有在 URL 的末尾添加 .json。谢谢你。这是解决方案:

Firebase_Url = 'https://***.firebaseio.com/Channel1.json';
response = webwrite(Firebase_Url,'{ "first": "Jack", "last": "Sparrow" }')

【讨论】:

    猜你喜欢
    • 2016-02-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-06-26
    • 2021-12-21
    • 1970-01-01
    • 2016-12-13
    相关资源
    最近更新 更多