列出 reCAPTCHA Enterprise 網站金鑰
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["難以理解","hardToUnderstand","thumb-down"],["資訊或程式碼範例有誤","incorrectInformationOrSampleCode","thumb-down"],["缺少我需要的資訊/範例","missingTheInformationSamplesINeed","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],[],[],[],null,["# List reCAPTCHA Enterprise site keys\n\nList all keys present for the given project ID.\n\nCode sample\n-----------\n\n### Java\n\n\nTo authenticate to reCAPTCHA, 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\n import com.google.cloud.recaptchaenterprise.v1.https://cloud.google.com/java/docs/reference/google-cloud-recaptchaenterprise/latest/com.google.cloud.recaptchaenterprise.v1.RecaptchaEnterpriseServiceClient.html;\n import com.google.cloud.recaptchaenterprise.v1.https://cloud.google.com/java/docs/reference/google-cloud-recaptchaenterprise/latest/com.google.cloud.recaptchaenterprise.v1.RecaptchaEnterpriseServiceClient.html.https://cloud.google.com/java/docs/reference/google-cloud-recaptchaenterprise/latest/com.google.cloud.recaptchaenterprise.v1.RecaptchaEnterpriseServiceClient.ListKeysPagedResponse.html;\n import com.google.recaptchaenterprise.v1.https://cloud.google.com/java/docs/reference/google-cloud-recaptchaenterprise/latest/com.google.recaptchaenterprise.v1.Key.html;\n import com.google.recaptchaenterprise.v1.https://cloud.google.com/java/docs/reference/google-cloud-recaptchaenterprise/latest/com.google.recaptchaenterprise.v1.ListKeysRequest.html;\n import com.google.recaptchaenterprise.v1.https://cloud.google.com/java/docs/reference/google-cloud-recaptchaenterprise/latest/com.google.recaptchaenterprise.v1.ProjectName.html;\n import java.io.IOException;\n\n public class ListSiteKeys {\n\n public static void main(String[] args) throws IOException {\n // TODO(developer): Replace these variables before running the sample.\n String projectID = \"your-project-id\";\n\n listSiteKeys(projectID);\n }\n\n /**\n * List all keys present under the given project ID.\n *\n * @param projectID : GCloud Project ID.\n */\n public static https://cloud.google.com/java/docs/reference/google-cloud-recaptchaenterprise/latest/com.google.cloud.recaptchaenterprise.v1.RecaptchaEnterpriseServiceClient.ListKeysPagedResponse.html listSiteKeys(String projectID) throws IOException {\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 `client.close()` method on the client to safely\n // clean up any remaining background resources.\n try (https://cloud.google.com/java/docs/reference/google-cloud-recaptchaenterprise/latest/com.google.cloud.recaptchaenterprise.v1.RecaptchaEnterpriseServiceClient.html client = https://cloud.google.com/java/docs/reference/google-cloud-recaptchaenterprise/latest/com.google.cloud.recaptchaenterprise.v1.RecaptchaEnterpriseServiceClient.html.create()) {\n // Set the project ID to list the keys present in it.\n https://cloud.google.com/java/docs/reference/google-cloud-recaptchaenterprise/latest/com.google.recaptchaenterprise.v1.ListKeysRequest.html listKeysRequest =\n https://cloud.google.com/java/docs/reference/google-cloud-recaptchaenterprise/latest/com.google.recaptchaenterprise.v1.ListKeysRequest.html.newBuilder().setParent(https://cloud.google.com/java/docs/reference/google-cloud-recaptchaenterprise/latest/com.google.recaptchaenterprise.v1.ProjectName.html.of(projectID).toString()).build();\n\n https://cloud.google.com/java/docs/reference/google-cloud-recaptchaenterprise/latest/com.google.cloud.recaptchaenterprise.v1.RecaptchaEnterpriseServiceClient.ListKeysPagedResponse.html response = client.listKeys(listKeysRequest);\n System.out.println(\"Listing reCAPTCHA site keys: \");\n for (https://cloud.google.com/java/docs/reference/google-cloud-recaptchaenterprise/latest/com.google.recaptchaenterprise.v1.Key.html key : response.iterateAll()) {\n System.out.println(key.getName());\n }\n return response;\n }\n }\n }\n\n### PHP\n\n\nTo authenticate to reCAPTCHA, 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\\ApiCore\\ApiException;\n use Google\\Cloud\\RecaptchaEnterprise\\V1\\Client\\RecaptchaEnterpriseServiceClient;\n use Google\\Cloud\\RecaptchaEnterprise\\V1\\ListKeysRequest;\n\n /**\n * List all the reCAPTCHA keys associate to a Google Cloud project\n *\n * @param string $projectId Your Google Cloud project ID\n */\n function list_keys(string $projectId): void\n {\n $client = new RecaptchaEnterpriseServiceClient();\n $formattedProject = $client-\u003eprojectName($projectId);\n\n try {\n $listKeysRequest = (new ListKeysRequest())\n -\u003esetParent($formattedProject)\n -\u003esetPageSize(2);\n $response = $client-\u003elistKeys($listKeysRequest);\n\n print('Keys fetched' . PHP_EOL);\n\n // Either iterate over all the keys and let the library handle the paging\n foreach ($response-\u003eiterateAllElements() as $key) {\n print($key-\u003egetDisplayName() . PHP_EOL);\n }\n\n // Or fetch each page and process the keys as needed\n // foreach ($response-\u003eiteratePages() as $page) {\n // foreach ($page as $key) {\n // print($key-\u003egetDisplayName() . PHP_EOL);\n // }\n // }\n } catch (ApiException $e) {\n print('listKeys() call failed with the following error: ');\n print($e);\n }\n }\n\n### Python\n\n\nTo authenticate to reCAPTCHA, 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 https://cloud.google.com/python/docs/reference/recaptchaenterprise/latest/\n from google.cloud.recaptchaenterprise_v1.services.recaptcha_enterprise_service.pagers import (\n https://cloud.google.com/python/docs/reference/recaptchaenterprise/latest/google.cloud.recaptchaenterprise_v1.services.recaptcha_enterprise_service.pagers.ListKeysPager.html,\n )\n\n\n def list_site_keys(project_id: str) -\u003e ListKeysPager:\n \"\"\"List all keys present under the given project ID.\n\n Args:\n project_id: GCloud Project ID.\n \"\"\"\n\n project_name = f\"projects/{project_id}\"\n\n client = https://cloud.google.com/python/docs/reference/recaptchaenterprise/latest/.https://cloud.google.com/python/docs/reference/recaptchaenterprise/latest/google.cloud.recaptchaenterprise_v1.services.recaptcha_enterprise_service.RecaptchaEnterpriseServiceClient.html()\n\n # Set the project id to list the keys present in it.\n request = https://cloud.google.com/python/docs/reference/recaptchaenterprise/latest/.https://cloud.google.com/python/docs/reference/recaptchaenterprise/latest/google.cloud.recaptchaenterprise_v1.types.ListKeysRequest.html()\n request.parent = project_name\n\n response = client.https://cloud.google.com/python/docs/reference/recaptchaenterprise/latest/google.cloud.recaptchaenterprise_v1.services.recaptcha_enterprise_service.RecaptchaEnterpriseServiceClient.html#google_cloud_recaptchaenterprise_v1_services_recaptcha_enterprise_service_RecaptchaEnterpriseServiceClient_list_keys(request)\n print(\"Listing reCAPTCHA site keys: \")\n for i, key in enumerate(response):\n print(f\"{str(i)}. {key.name}\")\n\n return response\n\n### Ruby\n\n\nTo authenticate to reCAPTCHA, 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 require \"google/cloud/recaptcha_enterprise\"\n\n # List all site keys registered to use recaptcha services.\n #\n # @param project_id [String] GCloud Project ID.\n # @return [void]\n def list_site_keys project_id:\n # Create the reCAPTCHA client.\n client = ::Google::Cloud::RecaptchaEnterprise.recaptcha_enterprise_service\n\n response = client.list_keys parent: \"projects/#{project_id}\"\n puts \"Listing reCAPTCHA site keys: \"\n response.each do |key|\n puts key.name\n end\n end\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=recaptcha_enterprise)."]]