【发布时间】:2018-10-11 02:02:33
【问题描述】:
我一直在搜索如何使用颤振应用程序实现 firebase 功能。似乎没有可用的 SDK(还)。我还尝试将 gradle 依赖项 implementation 'com.google.firebase:firebase-functions:15.0.0' 添加到我的 app/build.gradle 中,但这会导致构建错误。
有人做过有效的实现吗?我找不到任何有关如何处理凭据和数据传输以构建我自己的 firebase 函数调用的文档。
我已经大致勾勒出我认为这是如何工作的,但可能有点离谱。
Future<dynamic> updateProfile(String uid, AccountMasterViewModel avm) async {
Uri uri = Uri.parse(finalizeProfileFunctionURL);
var httpClient = new HttpClient();
String _result = '';
try {
return await httpClient
.postUrl(uri)
.then((HttpClientRequest request) {
return request.close();
// authentication??
// Fields and data??
})
.then((HttpClientResponse response) async {
print(response.transform(new Utf8Codec().decoder).join());
if (response.statusCode == HttpStatus.OK) {
String json = await response.transform(new Utf8Codec().decoder).join();
_result = jsonDecode(json);
// Do some work
return json;
}
else {
return ':\nHttp status ${response.statusCode}';
}
});
}
catch (exception) {
return 'Failed ' + exception.toString();
}
}
我希望能够发送一个对象,例如
{
accountID: src.accountID,
accountName: src.name,
accountImg: src.image
}
然后处理响应。但正如我所说,我找不到任何关于如何做到这一点的工作示例或教程。做这个客户端大小并直接与数据库对话是相当简单的,但是,有一些验证和数据组件需要对客户端隐藏,所以云功能是我想要这样做的方式。
【问题讨论】:
-
实际上从 Flutter 应用程序的角度来看,HTTPS 云函数就像一个 REST API(除非游戏中有一些 Firebase 身份验证......)。例如。您将对象发布到端点并取回对象(或错误)。因此,由于它是后端的云功能,因此您不应该遇到任何困难。您不应在 Flutter 代码中声明任何有关 CF 的内容,例如 implementation 'com.google.firebase:firebase-functions:15.0.0
-
关于如何对 HTTP 请求使用身份验证,请参阅stackoverflow.com/questions/48477625/…
标签: firebase google-cloud-functions flutter