根据这里的Quickblox文档,可以使用以下示例从flutter SDK更新自定义对象:
String className = "TestFlutterClass";
String id = "5d4175afa0eb4715cae5b63f";
Map<String, Object> fieldsMap = Map();
fieldsMap['testString'] = "testField1";
fieldsMap['testInteger'] = 123;
fieldsMap['testBoolean'] = true;
try {
QBCustomObject? customObject = await QB.data.update(className, id: id, fields: fieldsMap);
} on PlatformException catch (e) {
// Some error occurred, look at the exception message for more details
}
上面的代码似乎不起作用,也没有返回任何东西。
我还尝试通过发布HTTP来更新自定义对象到Rest API使用下面的代码
String url = "https://api.quickblox.com/data/GAMES/61794c291558ea0059ce2c90.json";
Map map = {'data': { 'PLAYERS_STATUS': sts},};
await apiRequest(url, map);
Future<String> apiRequest(String url, Map jsonMap) async {
HttpClient httpClient = new HttpClient();
HttpClientRequest request = await httpClient.postUrl(Uri.parse(url));
request.headers.set('content-type', 'application/json');
request.headers.set('QB-token', session);
request.add(utf8.encode(json.encode(jsonMap)));
HttpClientResponse response = await request.close();
// todo - you should check the response.statusCode
String reply = await response.transform(utf8.decoder).join();
httpClient.close();
return reply;
}
这段代码返回一个带有消息
的错误资源未找到
现在我知道记录存在,因为我可以在仪表板上看到记录,并且所有类权限都是打开的。
欢迎任何帮助!
在服务器API中更新记录需要使用PUT请求方法。我可以看到你发送POST请求。尝试使用PUT请求方法代替POST https://api.flutter.dev/flutter/dart-io/HttpClient/putUrl.html