Fitur Penelusuran Produk sedang dalam mode pemeliharaan. Untuk skalabilitas yang lebih baik dan fungsi yang sama dengan Product Search, gunakan Vision Warehouse.
Setelah selesai, kunci akun layanan Anda akan didownload ke lokasi default browser.
Selanjutnya, tentukan apakah Anda akan memberikan autentikasi akun layanan sebagai token pemilik atau menggunakan kredensial default aplikasi.
Token pemilik
Jika Anda memanggil Vision API secara langsung, misalnya dengan membuat permintaan HTTP dengan cURL, Anda harus meneruskan autentikasi sebagai token pemilik di header Authorization. Cara mendapatkan token pemilik menggunakan akun layanan Anda:
Jika Anda menggunakan library klien untuk memanggil Vision API, gunakan Kredensial Default Aplikasi (ADC).
Layanan yang menggunakan ADC mencari kredensial dalam variabel lingkungan GOOGLE_APPLICATION_CREDENTIALS. Kecuali jika Anda secara khusus ingin ADC menggunakan kredensial lain (misalnya, kredensial pengguna), sebaiknya tetapkan variabel lingkungan ini agar mengarah ke file kunci akun layanan Anda.
Ganti PATH_TO_KEY_FILE dengan jalur ke file akun layanan JSON Anda.
GOOGLE_APPLICATION_CREDENTIALS harus ditulis apa adanya (bukan placeholder dalam contoh di atas).
Menggunakan kunci API
Anda dapat menggunakan kunci API konsol Google Cloud untuk mengautentikasi ke Vision API.
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Sulit dipahami","hardToUnderstand","thumb-down"],["Informasi atau kode contoh salah","incorrectInformationOrSampleCode","thumb-down"],["Informasi/contoh yang saya butuhkan tidak ada","missingTheInformationSamplesINeed","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],["Terakhir diperbarui pada 2025-09-02 UTC."],[],[],null,["# Authenticating to the Cloud Vision API\n\nUsing a service account\n-----------------------\n\nUsing a service account to authenticate is the preferred method. To use a\nservice account to authenticate to the Vision API:\n\n1. Follow the instructions to [create a service account](/iam/docs/creating-managing-service-accounts#creating_a_service_account). Select **JSON** as your key type.\n\nOnce complete, your service account key is downloaded to your browser's\ndefault location.\n\nNext, decide whether you'll provide your service account authentication as a\n**bearer token** or using **application default credentials**.\n\n### Bearer tokens\n\nIf you're calling the Vision API directly, such as by making an HTTP request\nwith cURL, you'll pass your authentication as a bearer token in an\n`Authorization` header. To obtain a bearer token using your service account:\n\n1. [Install the gcloud CLI](/sdk/downloads#interactive).\n2. Authenticate to your service account, replacing `KEY_FILE` below with the\n path to your service account key file:\n\n gcloud auth activate-service-account --key-file KEY_FILE\n\n3. Obtain an authorization token using your service account:\n\n gcloud auth print-access-token\n\n The command returns an access token value.\n4. When calling the API, obtain an authorization token using your service\n account in an `Authorization` header:\n\n curl -s -H \"Authorization: Bearer $(gcloud auth application-default print-access-token)\" \\\n -H \"Content-Type: application/json\" \\\n \"https://vision.googleapis.com/v1/images:annotate\" -d @request.json\n\n### Application default credentials\n\nIf you're using a client library to call the Vision API, use\n[Application Default Credentials](https://developers.google.com/identity/protocols/application-default-credentials) (ADC).\nServices using ADC look for credentials within a `GOOGLE_APPLICATION_CREDENTIALS`\nenvironment variable. Unless you specifically wish to have ADC use other\ncredentials (for example, user credentials), we recommend you set this\nenvironment variable to point to your service account key file. \n\n```\nexport GOOGLE_APPLICATION_CREDENTIALS=PATH_TO_KEY_FILE\n```\n\nReplace `PATH_TO_KEY_FILE` with the path to your JSON service account file.\n`GOOGLE_APPLICATION_CREDENTIALS` should be written out as-is (it's not a\nplaceholder in the example above).\n\nUsing an API key\n----------------\n\nYou can use a Google Cloud console API key to authenticate to the Vision API.\n\nTo do so:\n\n1. Follow the instructions to\n [create an API key for your Google Cloud console project](https://support.google.com/cloud/answer/6158862?hl=en).\n\n2. When making any Vision API request, pass your key as the value of a `key`\n parameter. For example:\n\n POST https://vision.googleapis.com/v1/images:annotate?key=YOUR_API_KEY\n\nMake sure to read\n[Best practices for securely using API keys](https://support.google.com/cloud/answer/6310037?hl=en&ref_topic=6262490)\nto prevent unauthorized use of your API key."]]