如何使用 Cloud Functions 以使用 Firebase Cloud vision
How to use the Cloud Functions in order to use Firebase Cloud vision
我最近刚刚将我的 Firebase 帐户升级到 blaze,以试用 Firebase 的机器学习功能。我正在密切关注 google 的本指南:
https://firebase.google.com/docs/ml/android/recognize-text
(阅读这篇文章将是必不可少的,因为我将不断参考它)
我已经完成了每一步,直到第二点,这给我带来了问题:
- Invoke the callable function to recognize text.
To recognize text in an image, invoke the callable function, passing a JSON Cloud Vision request.
First, initialize an instance of Cloud Functions:
private lateinit var functions: FirebaseFunctions
// ...
functions = Firebase.functions
如果我做对了,FirebaseFunction 类型的“函数”应该是他告诉我预先通过命令行部署的函数。
但我不明白这些函数应该放在哪里,因此 Android Studio 无法识别引用“Firebase.functions”,正如您在这张图片中看到的那样。
功能部署成功,但在本指南的任何地方我都发现我应该把这些功能放在哪里...我哪里错了?我对 Firebase 仍然是一个极度菜鸟,所以请耐心等待。
您使用的代码使用了 Cloud Functions for Firebase 的 Kotlin 扩展。因此,请务必在 build.gradle
中包含 Kotlin 扩展库(通常称为 ktx
),如 setting up your Android app:
上的文档所示
dependencies {
// Import the BoM for the Firebase platform
implementation platform('com.google.firebase:firebase-bom:28.4.0')
// Declare the dependency for the Cloud Functions library
// When using the BoM, you don't specify versions in Firebase library dependencies
implementation 'com.google.firebase:firebase-functions-ktx' // don't forget
}
我最近刚刚将我的 Firebase 帐户升级到 blaze,以试用 Firebase 的机器学习功能。我正在密切关注 google 的本指南: https://firebase.google.com/docs/ml/android/recognize-text (阅读这篇文章将是必不可少的,因为我将不断参考它)
我已经完成了每一步,直到第二点,这给我带来了问题:
- Invoke the callable function to recognize text.
To recognize text in an image, invoke the callable function, passing a JSON Cloud Vision request.
First, initialize an instance of Cloud Functions:
private lateinit var functions: FirebaseFunctions // ... functions = Firebase.functions
如果我做对了,FirebaseFunction 类型的“函数”应该是他告诉我预先通过命令行部署的函数。 但我不明白这些函数应该放在哪里,因此 Android Studio 无法识别引用“Firebase.functions”,正如您在这张图片中看到的那样。
功能部署成功,但在本指南的任何地方我都发现我应该把这些功能放在哪里...我哪里错了?我对 Firebase 仍然是一个极度菜鸟,所以请耐心等待。
您使用的代码使用了 Cloud Functions for Firebase 的 Kotlin 扩展。因此,请务必在 build.gradle
中包含 Kotlin 扩展库(通常称为 ktx
),如 setting up your Android app:
dependencies {
// Import the BoM for the Firebase platform
implementation platform('com.google.firebase:firebase-bom:28.4.0')
// Declare the dependency for the Cloud Functions library
// When using the BoM, you don't specify versions in Firebase library dependencies
implementation 'com.google.firebase:firebase-functions-ktx' // don't forget
}