gpt4 book ai didi

firebase - Firebase Cloud Firestore无法正常工作

转载 作者:行者123 更新时间:2023-12-03 04:09:54 26 4
gpt4 key购买 nike

我正在构建使用Cloud Firestore的应用程序。问题是Firestore无法正常工作。这是我正在使用的代码
达特

class Db{

// collection reference
static final CollectionReference _collectionReference = Firestore.instance.collection("codes");

static Future addOrUpdateCode(String code , double lat , double long) async {
return await _collectionReference.document(code).setData({
'lat':lat,
'long':long
});
}

}
我已经在pubspec.yaml中添加了这一行
cloud_firestore: ^0.13.7
我收到这些错误
I/BiChannelGoogleApi(13145): [FirebaseAuth: ] getGoogleApiForMethod() returned Gms: com.google.firebase.auth.api.internal.zzaq@b61eba8
W/Firestore(13145): (21.3.0) [FirestoreCallCredentials]: Failed to get token: com.google.firebase.FirebaseException: An internal error has occurred. [ yRequests to this API securetoken.googleapis.com method google.identity.securetoken.v1.SecureToken.GrantToken are blocked.�
W/Firestore(13145): #type.googleapis.com/google.rpc.Helpq
W/Firestore(13145): o
W/Firestore(13145): Google developer console API keyKhttps://console.developers.google.com/project/280924879656/apiui/credential ].
I/BiChannelGoogleApi(13145): [FirebaseAuth: ] getGoogleApiForMethod() returned Gms: com.google.firebase.auth.api.internal.zzaq@b61eba8
W/Firestore(13145): (21.3.0) [FirestoreCallCredentials]: Failed to get token: com.google.firebase.FirebaseException: An internal error has occurred. [ yRequests to this API securetoken.googleapis.com method google.identity.securetoken.v1.SecureToken.GrantToken are blocked.�
W/Firestore(13145): #type.googleapis.com/google.rpc.Helpq
W/Firestore(13145): o
W/Firestore(13145): Google developer console API keyKhttps://console.developers.google.com/project/280924879656/apiui/credential ].
I/BiChannelGoogleApi(13145): [FirebaseAuth: ] getGoogleApiForMethod() returned Gms: com.google.firebase.auth.api.internal.zzaq@b61eba8
在云控制台中启用了以下API
enter image description here
通过在Firebase中启用的电子邮件/密码注册
我正在使用这些规则
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if false;
}
}
}
我相信足够的信息。感谢您的时间。

最佳答案

Firestore安全规则配置不正确。参见Get started with Cloud Firestore Security Rules
既然您提到要实现Firebase身份验证,那么您将需要像它们提供的示例一样的东西:

// Allow read/write access on all documents to any user signed in to the application
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if request.auth != null;
}
}
}
但是请注意,您可能还会想要通过自定义 token 进行多级管理。查看 Create Custom Tokens,您可能最终会得到类似规则的内容,该规则允许管理员访问所有内容,然后从此处缩小访问范围,例如:
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if request.auth.token.admin == true;
}
match /users/{userId} {
allow read, write: if request.auth.uid == userId;
}
}
}

关于firebase - Firebase Cloud Firestore无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62854485/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com