从Matlab向Firebase发送数据

时间:2018-11-26 14:43:28

标签: matlab rest firebase

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

我正在像Matlab一样从Matlab进行API调用:

    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)

2 个答案:

答案 0 :(得分:0)

通过阅读mathworks documentation on webwrite,您需要使用该方法的两参数版本,并将附加信息传递到第二个data对象中:

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

response = webwrite(FirebaseURL,data)

答案 1 :(得分:0)

好吧,我发现解决方案显然没有在URL末尾添加.json。谢谢。解决方法如下:

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