首页 > 解决方案 > Cloud Firestore REST API - 创建文档时出现 400 错误请求

问题描述

我在 Unity (C#) 中使用 Cloud Firestore REST API 并尝试创建一个文档。但是,写入一直失败,错误代码为 400。这是我的代码:

string test = "{\"fields\": { \"field1\": {\"stringValue\": \"hello world\"}}}";
using (UnityWebRequest www = UnityWebRequest.Post($"https://firestore.googleapis.com/v1/projects/{PROJECT_ID}/databases/(default)/documents/{path}", test))
    {
    yield return www.SendWebRequest();
    if (www.isNetworkError || www.isHttpError)
    {
        Debug.Log(doc.ToJson());
        Debug.Log($"Write failed: {www.error}");
    }
}

奇怪的是,我一直在使用 API Explorer 并且完全相同的有效负载在那里工作。url 与资源管理器生成的相同,减去 API 密钥,但添加并不能解决问题。我错过了什么?

标签: firebasegoogle-cloud-firestore

解决方案


推荐阅读