首页 > 解决方案 > Firestore C#:权限缺失或不足

问题描述

我目前正在 C# 中探索 Firebase 的 Cloud Firestore,并遇到了在搜索 SO 后无法解决的错误。似乎 C# 中 Firestore 的资源非常有限:

"Status(StatusCode=PermissionDenied, Detail=\"Missing or insufficient permissions.\")"

到目前为止我的代码:

class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine("Hello World!");
        Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", "FirebaseCsharpTest.json");

        string project = "MyProjectId";

        FirestoreDb db = FirestoreDb.Create(project);
        Console.WriteLine("Created Cloud Firestore client with project ID: {0}", project);

        AddPerson(db).GetAwaiter().GetResult();

    }

    public static async Task AddPerson(FirestoreDb db)
    {
        CollectionReference collection = db.Collection("users");
        DocumentReference document = await collection.AddAsync(new
        {
            Name = new
            { First = "Ada", Last = "Lovelace" },
            Born = 1815
        });
    }
}

我已经在我的 Firebase 控制台上检查了 Firestore 安全规则是否设置为公开(截至目前,为了测试)。我还确保身份验证json文件是从 Google Developer Console 生成的正确文件,如本文中所建议的那样

有什么我想念的吗?

编辑:我对谷歌云控制台的权限: 在此处输入图像描述

标签: c#firebasegoogle-cloud-firestore

解决方案


请检查您添加的项目 ID。ProjectID 应该是您的 json 文件中指定的那个。


推荐阅读