简体   繁体   English

如何让我的 Google-service.json 在 Google Cloud Plataform 中与 Firestore 一起使用?

[英]How do I get my Google-service.json working with Firestore inside Google Cloud Plataform?

I'm using the google cloud platform to make my system.我正在使用谷歌云平台来制作我的系统。 Inside of it has a Firestore system, that use the same API and packages that the outside (outside of the Google Cloud Platform) use.它内部有一个 Firestore 系统,使用相同的 API 和外部(谷歌云平台之外)使用的包。

I know that using the outside one you can generate a Json to use as a key to work with the FireStore Module inside flutter/dart.我知道使用外部可以生成一个 Json 作为密钥来使用 flutter/dart 中的 FireStore 模块。 But using the inside Firestore GCP, you just can generate a GCP Key, and not a Firestore key.但是使用内部 Firestore GCP,您只能生成 GCP 密钥,而不是 Firestore 密钥。 Even using the "firestore adm" option in the key generator.即使在密钥生成器中使用“firestore adm”选项。

Here the simple code that I'm using to start the Firestore thing这是我用来启动 Firestore 的简单代码

import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_core/firebase_core.dart';

FirebaseFirestore firestore = FirebaseFirestore.instance;

bool teste() {
  Firebase.initializeApp();
  //print(firestore.collection("users").snapshots());

  return false;
}

And here the bug that appears to me when I try to use the GCP key:这是我尝试使用 GCP 密钥时出现的错误:

E/flutter (11150): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: [core/not-initialized] Firebase has not been correctly initialized. Have you added the "google-services.json" file to the project?
E/flutter (11150):
E/flutter (11150):     View the Android Installation documentation for more information: https://firebaseextended.github.io/flutterfire/docs/installation/android
E/flutter (11150):
E/flutter (11150): #0      MethodChannelFirebase.initializeApp (package:firebase_core_platform_interface/src/method_channel/method_channel_firebase.dart:86:9)
E/flutter (11150): <asynchronous suspension>
E/flutter (11150): #1      Firebase.initializeApp (package:firebase_core/src/firebase.dart:43:25)
E/flutter (11150): #2      teste (package:invideo_finder/backend/verifyFireBase.dart:7:12)
E/flutter (11150): #3      _RegisterPageState.verifyUser.<anonymous closure> (package:invideo_finder/pages/register.dart:51:11)
E/flutter (11150): #4      State.setState (package:flutter/src/widgets/framework.dart:1244:30)
E/flutter (11150): #5      _RegisterPageState.verifyUser (package:invideo_finder/pages/register.dart:34:5)
E/flutter (11150): #6      _RegisterPageState.onPressButton (package:invideo_finder/pages/register.dart:69:27)
E/flutter (11150): #7      _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:993:19)
E/flutter (11150): #8      _InkResponseState.build.<anonymous closure> (package:flutter/src/material/ink_well.dart:1111:38)
E/flutter (11150): #9      GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:183:24)
E/flutter (11150): #10     TapGestureRecognizer.handleTapUp (package:flutter/src/gestures/tap.dart:598:11)
E/flutter (11150): #11     BaseTapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:287:5)
E/flutter (11150): #12     BaseTapGestureRecognizer.handlePrimaryPointer (package:flutter/src/gestures/tap.dart:222:7)
E/flutter (11150): #13     PrimaryPointerGestureRecognizer.handleEvent (package:flutter/src/gestures/recognizer.dart:476:9)
E/flutter (11150): #14     PointerRouter._dispatch (package:flutter/src/gestures/pointer_router.dart:77:12)
E/flutter (11150): #15     PointerRouter._dispatchEventToRoutes.<anonymous closure> (package:flutter/src/gestures/pointer_router.dart:122:9)
E/flutter (11150): #16     _LinkedHashMapMixin.forEach (dart:collection-patch/compact_hash.dart:377:8)
E/flutter (11150): #17     PointerRouter._dispatchEventToRoutes (package:flutter/src/gestures/pointer_router.dart:120:18)
E/flutter (11150): #18     PointerRouter.route (package:flutter/src/gestures/pointer_router.dart:106:7)
E/flutter (11150): #19     GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:358:19)
E/flutter (11150): #20     GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:338:22)
E/flutter (11150): #21     RendererBinding.dispatchEvent (package:flutter/src/rendering/binding.dart:267:11)
E/flutter (11150): #22     GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:295:7)
E/flutter (11150): #23     GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:240:7)
E/flutter (11150): #24     GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:213:7)
E/flutter (11150): #25     _rootRunUnary (dart:async/zone.dart:1206:13)
E/flutter (11150): #26     _CustomZone.runUnary (dart:async/zone.dart:1100:19)
E/flutter (11150): #27     _CustomZone.runUnaryGuarded (dart:async/zone.dart:1005:7)

Some one can, please help me with it?有人可以,请帮助我吗? I don't have any idea of what to do.我不知道该怎么做。

The google-services.json contains the credentials in order for yur app to access the services in GCP therefore You can use a credentials.json that can be generated for a service account. google-services.json包含凭据,以便您的应用程序访问 GCP 中的服务,因此您可以使用可以为服务帐户生成的credentials.json 。json。 following the next steps :以下步骤

  • Create a service account创建服务帐号

    • Go the the Service Account Page Go服务帐号页面
    • Click on Create Service Account单击创建服务帐户
    • Enter its name, and description输入它的名称和描述
    • Click on Create点击创建
    • Select the roles you need to access the services you are going to use from your app Select 访问您将要从您的应用程序使用的服务所需的角色
    • Click on Continue点击继续
    • Click on Done点击完成
  • Click on the Service account you are using单击您正在使用的服务帐户

  • Click on Add Key点击添加密钥

  • Select JSON Select JSON

  • Click on Create点击创建

These steps will allow you to create a service accound and download its Credentials.json file.这些步骤将允许您创建服务帐户并下载其Credentials.json文件。

In case you want to use the google-services.json this file is the one generated by Firebase, and can be downloaded from the firebase console after registering an app there.如果您想使用google-services.json ,此文件是由 Firebase 生成的文件,可以在 firebase 控制台注册应用程序后从控制台下载。

Consider that when you have a GCP project you can enable firebase on it by accessing the Firebase Console and accessing to your project.考虑一下,当您有一个 GCP 项目时,您可以通过访问Firebase 控制台并访问您的项目来在其上启用 firebase。 and all the resources compatible with both platforms will be shared, including Firestore所有与两个平台兼容的资源将被共享,包括 Firestore

I am not sure if you are aware that you can actually access your project google-services.json file in your Firebase console.我不确定您是否知道您实际上可以在 Firebase 控制台中访问您的项目 google-services.json 文件。 This is the correct way of using Firebase services.这才是Firebase服务的正确使用方式。

You can get the file in your project settings on Firebase Console.您可以在 Firebase 控制台的项目设置中获取该文件。

It looks like if you have an firestore in Google cloud plataform you have one in FireBase plataform too, I didn't knew this看起来如果你在谷歌云平台上有一个 firestore 你在 FireBase 平台上也有一个,我不知道这个

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Firebase 身份验证和 google-service.json - Firebase authentication and google-service.json 如何删除 Google Cloud Firestore 中项目的所有 collections? - How do I delete ALL collections for a project in Google Cloud Firestore? 如何在 python 程序中定义我的 Google Cloud Platform 服务帐户的密钥? - How do I define my Google Cloud Platform service account's key in a python program? 如何在 Google Cloud 服务上找到 IPv4 地址? - How do I find the IPv4 address on a Google Cloud service? 如何使用 Firestore 删除现有 Google Cloud 项目中的 AppEngine 默认服务 - How to delete AppEngine default service in the existing Google Cloud project with Firestore 将 android 工作室的 google-service.json 更改为 firebase_option.dart 项目项目 Z5ACEBC4CB70DDBBAEZB0AC76AAB176 - Change google-service.json from android studio to firebase_option.dart on flutter project 如何在 Google Cloud Functions 中获取当前的 projectId? - How can I get current projectId inside Google Cloud Functions? 如何删除我的 Google Cloud Platform 帐户? - How do I delete my Google Cloud Platform Account? 如何让 Google Cloud Build 在 VPC 边界内工作? - How to get Google Cloud Build working inside VPC Perimeter? 允许外部用户使用谷歌云平台账户 - Allow an external user to use Google Cloud Plataform account
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM