我想从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)
通过阅读webwrite
上的mathworks文档,您需要使用该方法的两个参数版本,在第二个data
对象中传递附加信息:
data = ['api_key=',writeApiKey,'&name=',"JSOpn9ZC54A4P4RoqVa"];
response = webwrite(FirebaseURL,data)
好的,我找到了解决方案,显然我没有在URL的末尾添加.json。非常感谢。以下是解决方案:
Firebase_Url = 'https://***.firebaseio.com/Channel1.json';
response = webwrite(Firebase_Url,'{ "first": "Jack", "last": "Sparrow" }')