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

abithluo  于 2022-11-30  发布在  C#
关注(0)|答案(1)|浏览(116)
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数据库检索数据

fruv7luv

fruv7luv1#

我发现你没有在firebaseconfig中定义auth密钥。请参阅github project

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);
                }
         });

相关问题