我有一个网站,它利用Azure上的sql Server来获取所有数据.我正在与另一家公司合作,为我的数据库中存在的特定记录获取额外的补充信息.
当正在查看这些“特定记录”时,我想提供另一个链接以从Firebase数据库中检索该补充信息.
所以,我正在尝试编写一个可以检索这些数据的服务,这就是我迄今为止所写的PoC:
private readonly string firebaseUrl = "https://{myproject}.firebaseio.com/"; private readonly string authToken = "x:xxxxxxxxxxx:xxx:xxxxxxxxxxxxxxxx"; public async Task<IEnumerable<InMatchStat>> GetInMatchStats() { try { var firebase = new FirebaseClient(firebaseUrl,new FirebaSEOptions { AuthTokenAsyncFactory = () => Task.Fromresult(authToken) }); var stats = await firebase.Child("my/collection/path").OnceAsync<InMatchStat>(); if (stats == null || !stats.Any()) { return null; } return await Convert(stats.AsEnumerable()); } catch (Exception exception) { var message = exception.ToString(); } return null; }
这是我在尝试执行var stats = await firebase.Child()…. call时从Firebase返回的错误:
firebase Could not parse auth token
这是FirebaseDatabase.NET Github页面的链接:https://github.com/step-up-labs/firebase-database-dotnet
如果链接在将来失效,这里是我正在尝试复制的确切示例,该示例显示在该站点上:
var auth = "ABCDE"; // your app secret var firebaseClient = new FirebaseClient( "<URL>",new FirebaSEOptions { AuthTokenAsyncFactory = () => Task.Fromresult(auth) });
var firebase = new FirebaseClient("https://dinosaur-facts.firebaseio.com/"); var dinos = await firebase .Child("dinosaurs") .OrderByKey() .StartAt("pterodactyl") .LimitToFirst(2) .OnceAsync<Dinosaur>(); foreach (var dino in dinos) { Console.WriteLine($"{dino.Key} is {dino.Object.Height}m high."); }
我的实施在哪里出错了?
解决方法
只是想让这个更新,因为我终于想出了解决方案,对我来说……
这是我从中获得解决方案的地方:https://github.com/step-up-labs/firebase-database-dotnet/issues/60
此版本传递电子邮件地址和密码以获取身份验证令牌.然后,一旦我们拥有令牌,就会像以前一样将其传递给Firebase客户端.
(注意:我需要添加FirebaseAuthentication.net nuget包)
public async Task<IEnumerable<InMatchStat>> GetInMatchStats() { const string firebaseUrl = "https://xxxxxxxxxxxxxx.firebaseio.com/"; const string firebaseUsername = "[email protected]"; const string firebasePassword = "xxxxxxxx"; const string firebaseApiKey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; bool tryAgain = false; FirebaseAuthLink token = null; try { var auth = new FirebaseAuthProvider(new FirebaseConfig(firebaseApiKey)); do { try { token = await auth.SignInWithEmailAndPasswordAsync(firebaseUsername,firebasePassword); } catch (FirebaseAuthException faException) { // checking for a false tryAgain because we don't want to try and create the account twice if (faException.Reason.ToString() == "UnkNownEmailAddress" && !tryAgain) { // create,then signin token = await auth.createuserWithEmailAndPasswordAsync(firebaseUsername,firebasePassword,"Greg",false); tryAgain = true; } throw; } catch (Exception) { throw; } } while (tryAgain); var firebase = new FirebaseClient(firebaseUrl,new FirebaSEOptions { AuthTokenAsyncFactory = () => Task.Fromresult(token.Firebasetoken) }); var stats = await firebase.Child("my/collection/path").OnceAsync<InMatchStat>(); if (stats == null || !stats.Any()) { return null; } //return await Convert(stats.AsEnumerable()); } catch (Exception exception) { var message = exception.ToString(); } return null; }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。