在c#中使用firesharp库从firebase实时数据库检索数据

问题描述 投票:0回答:1
IFirebaseConfig config = new FirebaseConfig();
config.Serializer = new ServiceStackJsonSerializer(); //Register ServiceStack.Text
config.Serializer = new JsonNetSerializer();          //Register Json.Net
config.AuthSecret = "authsecret here";
config.BasePath = "https://xyz.firebaseio.com/";
IFirebaseClient client = new FirebaseClient(config);
FirebaseResponse response = client.Get("abc/pqr");
Context.Response.Flush();
Context.Response.Write(response.ToString());

我收到错误响应“无法解析身份验证令牌”,我正在使用 FireSharp 库并尝试从 firebase 数据库检索数据

c# asp.net firebase firebase-realtime-database fire-sharp
1个回答
0
投票

我发现您没有在 firebaseconfig 中定义身份验证密钥。请参阅 github 项目

IFirebaseConfig config = new FirebaseConfig
{
     AuthSecret = "your-auth-secret",
     BasePath = "<your-firebase-reference-link>.firebaseio.com/"

};

IFirebaseClient client;

client = new FirebaseClient(config);
         await client.OnAsync("FireSharp/Name/", (sender, args) =>
         {
                //Gets the Unique ID and deletes the any other string attached to it
                string dataFromFB = args.Data;
                string paths = args.Path;
                string key = RemoveNameSubstring(paths);
                string uniqueKey = key.Split('/').Last();
                if (keyHolder.ContainsKey(uniqueKey))
                {
                    keyHolder[uniqueKey] = dataFromFB;
                    AddToListView(dataFromFB);
                }
                else
                {
                    keyHolder.Add(uniqueKey, dataFromFB);
                    AddToListView(dataFromFB);
                }
         });
© www.soinside.com 2019 - 2024. All rights reserved.