使用REST API结合Proyecto26更新Firebase Realtime Database用户单值的问题
C# 调用 REST API 操作 Firebase Realtime Database 更新用户字段踩坑记录
在C#项目开发中,调用REST API操作Firebase Realtime Database,尝试更新users路径下的用户单个字段值时,先后遇到多类问题,最终通过引入JSON.NET对请求数据做序列化处理的方式,成功解决全部问题。
实际遇到的问题如下:
- 首次发起PUT请求时触发编译报错:
error CS1503: Argument 1: cannot convert from 'string' to 'Proyecto26.RequestHelper',对应问题代码:
RestClient.Put($"{databaseURL}users/{userId}/{nodeUpdate}:{valueUpte}.json").Then(response =>
- 为上述Put方法补充空字符串作为第二参数后,编译报错消失,但更新请求未实际生效,对应代码:
RestClient.Put($"{databaseURL}users/{userId}/{nodeUpdate}:{valueUpte}.json","").Then(response =>
- 调整请求路径对应用户根节点,传入节点与值的元组作为请求体时,请求可被服务端接收,但会覆盖该用户下的其余原有节点,并生成额外默认节点,对应代码:
public static void UpdateUserInfo(string userId, string nodeUpdate, string valueUpte, UpdateUserInfoCallback callback) { Debug.Log("UpdateUserInfo Method"); RestClient.Put($"{databaseURL}users/{userId}.json", (nodeUpdate,valueUpte)).Then(response => { callback(); Debug.Log("The user info was successfully updated in the database"); }); }
- 调整请求路径指向需要更新的具体子节点,直接传入目标值作为请求体时,请求不会触发数据更新,对应代码:
RestClient.Put($"{databaseURL}users/{userId}/{nodeUpdate}.json", (valueUpte)).Then(response => { callback(); Debug.Log("The user info was successfully updated in the database"); });
内容的提问来源于stack exchange,提问作者Robert
相关产品推荐
相关产品推荐

