借助 Cloud Natural Language,您可以控制处理项目资源的位置。具体来说,您可以将 Cloud Natural Language 配置为仅在欧盟或美国对您的数据执行机器学习处理。
默认情况下,Cloud Natural Language 会在全球位置处理资源,这意味着 Cloud Natural Language 不保证您的资源将保留在特定位置或区域内。如果您选择欧盟位置,Google 只会在欧盟对您的数据执行机器学习。如果您选择美国位置,则 Google 只会在美国对其执行机器学习。您和您的用户可以从任意位置访问该数据。
使用 API 设置位置
Cloud Natural Language API 支持全球 API 端点 (language.googleapis.com)、欧盟端点 (eu-language.googleapis.com)、美国端点 (us-language.googleapis.com)。如需仅在欧盟处理您的数据,请在 REST API 调用中使用 URI eu-language.googleapis.com(而不是 language.googleapis.com)。如需仅在美国处理您的数据,请在 REST API 调用中使用 URI us-language.googleapis.com(而不是 language.googleapis.com)。
澳大利亚也提供文本审核 API,您可以在 REST API 调用中使用 URI au-language.googleapis.com(而不是 language.googleapis.com)来访问该 API。
使用客户端库设置位置
默认情况下,客户端库会访问全球 API 端点 (language.googleapis.com)。如需仅在欧盟或美国存储和处理您的数据,您需要明确设置相应端点。以下代码示例展示了如何配置此设置。
如需向 Natural Language 进行身份验证,请设置应用默认凭据。如需了解详情,请参阅为本地开发环境设置身份验证。
# Imports the Google Cloud client libraryfromgoogle.cloudimportlanguage_v1client_options={"api_endpoint":"eu-language.googleapis.com:443"}# Instantiates a client.client=language_v1.LanguageServiceClient(client_options=client_options)
如需向 Natural Language 进行身份验证,请设置应用默认凭据。如需了解详情,请参阅为本地开发环境设置身份验证。
LanguageServiceSettingssettings=LanguageServiceSettings.newBuilder().setEndpoint("eu-language.googleapis.com:443").build();// Initialize client that will be used to send requests. This client only needs to be created// once, and can be reused for multiple requests. After completing all of your requests, call// the "close" method on the client to safely clean up any remaining background resources.LanguageServiceClientclient=LanguageServiceClient.create(settings);
如需向 Natural Language 进行身份验证,请设置应用默认凭据。如需了解详情,请参阅为本地开发环境设置身份验证。
// Imports the Google Cloud client libraryconstlanguage=require('@google-cloud/language');// Specifies the location of the api endpointconstclientOptions={apiEndpoint:'eu-language.googleapis.com'};// Instantiates a clientconstclient=newlanguage.LanguageServiceClient(clientOptions);
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-09-02。"],[],[],null,["# Locations\n\nCloud Natural Language offers you some control over where the resources for your\nproject are processed. In particular, you can configure Cloud Natural Language to\nperform machine learning processing on your data only in the EU or the US.\n\nBy default Cloud Natural Language processes resources in a **Global** location,\nwhich means that Cloud Natural Language doesn't guarantee that your resources will\nremain within a particular location or region. If you choose the\n**European Union** location, Google will perform machine learning with it only\nin the EU. If you choose the **United States** location, Google will\nperform machine learning with it only in the US. You and your users\ncan access the data from any location.\n\nSetting the location using the API\n----------------------------------\n\nCloud Natural Language supports a global API endpoint (`language.googleapis.com`),\na European Union endpoint (`eu-language.googleapis.com`), and a United States\nendpoint (`us-language.googleapis.com`).\nTo process your data in the European Union only, use the URI\n`eu-language.googleapis.com` in place of `language.googleapis.com` for your REST API calls.\nTo process your data in the United States only, use the URI\n`us-language.googleapis.com` in place of `language.googleapis.com` for your REST API calls.\n\nThe text moderation API is also available in Australia, which can be accessed by using the URI `au-language.googleapis.com` in place of `language.googleapis.com` for your REST API calls.\n\nSetting the location using client libraries\n-------------------------------------------\n\nThe client libraries access the global API endpoint (`language.googleapis.com`)\nby default. To store and process your data in the European Union or United States only, you need to\nexplicitly set the endpoint. The code samples below show how to configure this setting. \n\n### Python\n\n\nTo learn how to install and use the client library for Natural Language, see\n[Natural Language client libraries](/natural-language/docs/reference/libraries).\n\n\nFor more information, see the\n[Natural Language Python API\nreference documentation](/python/docs/reference/language/latest).\n\n\nTo authenticate to Natural Language, 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 # Imports the Google Cloud client library\n from google.cloud import language_v1\n\n client_options = {\"api_endpoint\": \"eu-language.googleapis.com:443\"}\n\n # Instantiates a client.\n client = language_v1.LanguageServiceClient(client_options=client_options)\n\n### Java\n\n\nTo learn how to install and use the client library for Natural Language, see\n[Natural Language client libraries](/natural-language/docs/reference/libraries).\n\n\nFor more information, see the\n[Natural Language Java API\nreference documentation](/java/docs/reference/google-cloud-language/latest/overview).\n\n\nTo authenticate to Natural Language, 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 LanguageServiceSettings settings =\n LanguageServiceSettings.newBuilder().setEndpoint(\"eu-language.googleapis.com:443\").build();\n\n // Initialize client that will be used to send requests. This client only needs to be created\n // once, and can be reused for multiple requests. After completing all of your requests, call\n // the \"close\" method on the client to safely clean up any remaining background resources.\n LanguageServiceClient client = LanguageServiceClient.create(settings);\n\n### Node.js\n\n\nTo learn how to install and use the client library for Natural Language, see\n[Natural Language client libraries](/natural-language/docs/reference/libraries).\n\n\nFor more information, see the\n[Natural Language Node.js API\nreference documentation](/nodejs/docs/reference/language/latest).\n\n\nTo authenticate to Natural Language, 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 // Imports the Google Cloud client library\n const language = require('https://cloud.google.com/nodejs/docs/reference/language/latest/overview.html');\n\n // Specifies the location of the api endpoint\n const clientOptions = {apiEndpoint: 'eu-language.googleapis.com'};\n\n // Instantiates a client\n const client = new language.https://cloud.google.com/nodejs/docs/reference/language/latest/overview.html(clientOptions);\n\n\u003cbr /\u003e"]]