Criar cliente com ID do projeto
Mantenha tudo organizado com as coleções
Salve e categorize o conteúdo com base nas suas preferências.
Criar cliente com ID do projeto
Mais informações
Para ver a documentação detalhada que inclui este exemplo de código, consulte:
Exemplo de código
Exceto em caso de indicação contrária, o conteúdo desta página é licenciado de acordo com a Licença de atribuição 4.0 do Creative Commons, e as amostras de código são licenciadas de acordo com a Licença Apache 2.0. Para mais detalhes, consulte as políticas do site do Google Developers. Java é uma marca registrada da Oracle e/ou afiliadas.
[[["Fácil de entender","easyToUnderstand","thumb-up"],["Meu problema foi resolvido","solvedMyProblem","thumb-up"],["Outro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Informações incorretas ou exemplo de código","incorrectInformationOrSampleCode","thumb-down"],["Não contém as informações/amostras de que eu preciso","missingTheInformationSamplesINeed","thumb-down"],["Problema na tradução","translationIssue","thumb-down"],["Outro","otherDown","thumb-down"]],[],[[["\u003cp\u003eThis document provides code samples for creating a Cloud Firestore client with a specified project ID across C#, Java, PHP, and Python.\u003c/p\u003e\n"],["\u003cp\u003eAuthentication to Firestore requires setting up Application Default Credentials, as detailed in the provided link to local development environment setup.\u003c/p\u003e\n"],["\u003cp\u003eThe code examples demonstrate how to initialize the Firestore client, either with a provided project ID or by relying on the default project inferred from the environment.\u003c/p\u003e\n"],["\u003cp\u003eFurther documentation on managing, adding, and getting data within Cloud Firestore is accessible through the linked resources.\u003c/p\u003e\n"],["\u003cp\u003eThe google cloud sample browser can be used to find code samples for other google cloud products.\u003c/p\u003e\n"]]],[],null,["# Create Client with Project ID\n\nExplore further\n---------------\n\n\nFor detailed documentation that includes this code sample, see the following:\n\n- [Add and update data](/firestore/native/docs/manage-data/add-data)\n- [Add data to Cloud Firestore](https://firebase.google.com/docs/firestore/manage-data/add-data)\n- [Create a Firestore database by using a server client library](/firestore/native/docs/create-database-server-client-library)\n- [Get data with Cloud Firestore](https://firebase.google.com/docs/firestore/query-data/get-data)\n- [Get started with Cloud Firestore](https://firebase.google.com/docs/firestore/quickstart)\n- [Getting data](/firestore/native/docs/query-data/get-data)\n\nCode sample\n-----------\n\n### C#\n\n\nTo authenticate to Firestore, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n FirestoreDb db = FirestoreDb.Create(project);\n Console.WriteLine(\"Created Cloud Firestore client with project ID: {0}\", project);\n\n### Java\n\n\nTo authenticate to Firestore, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n FirestoreOptions firestoreOptions =\n FirestoreOptions.getDefaultInstance().toBuilder()\n .setProjectId(projectId)\n .setCredentials(GoogleCredentials.getApplicationDefault())\n .build();\n Firestore db = firestoreOptions.getService();\n\n### PHP\n\n\nTo authenticate to Firestore, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n use Google\\Cloud\\Firestore\\FirestoreClient;\n\n /**\n * Initialize Cloud Firestore with a provided project ID.\n *\n * @param string $projectId Your Google Cloud Project ID\n */\n function setup_client_create_with_project_id(string $projectId): void\n {\n // Create the Cloud Firestore client with a provided project ID.\n $db = new FirestoreClient([\n 'projectId' =\u003e $projectId,\n ]);\n printf('Created Cloud Firestore client with project ID: %s' . PHP_EOL, $projectId);\n }\n\n### Python\n\n\nTo authenticate to Firestore, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n from google.cloud import firestore\n\n # The `project` parameter is optional and represents which project the client\n # will act on behalf of. If not supplied, the client falls back to the default\n # project inferred from the environment.\n db = firestore.https://cloud.google.com/python/docs/reference/firestore/latest/google.cloud.firestore_v1.client.Client.html(project=\"my-project-id\")\n\nWhat's next\n-----------\n\n\nTo search and filter code samples for other Google Cloud products, see the\n[Google Cloud sample browser](/docs/samples?product=firestore)."]]