Menyiapkan Service Usage untuk lingkungan pengembangan
Service Usage API memungkinkan Anda mengelola API dan layanan di projectGoogle Cloud Anda. Dalam panduan memulai ini, Anda akan mengonfigurasi lingkungan pengembangan untuk berinteraksi dengan Service Usage API untuk tujuan pengujian.
- Untuk sebagian besar kasus penggunaan operasional, cara termudah untuk mengaktifkan dan menonaktifkan layanan adalah menggunakan konsol Google Cloud .
- Jika perlu membuat skrip, Anda dapat menggunakan Google Cloud CLI.
- Jika Anda perlu memprogram Service Usage API, gunakan salah satu library klien.
- Untuk bereksperimen dengan API, ikuti petunjuk penyiapan dalam panduan ini dan
gunakan perintah
curluntuk menguji API tanpa menyiapkan lingkungan pengembangan aplikasi lengkap.
Menyiapkan panggilan API secara langsung
Bagian ini menjelaskan langkah-langkah dasar yang diperlukan untuk menyiapkan lingkungan lokal Anda guna bereksperimen dengan Service Usage API menggunakan perintah curl. Panduan ini ditujukan bagi developer yang perlu memprogram Service Usage API.
Mengaktifkan Service Usage API
Untuk menggunakan Service Usage API, Anda harus mengaktifkannya terlebih dahulu di projectGoogle Cloud Anda.
- Login ke akun Google Cloud Anda. Jika Anda baru menggunakan Google Cloud, buat akun untuk mengevaluasi performa produk kami dalam skenario dunia nyata. Pelanggan baru juga mendapatkan kredit gratis senilai $300 untuk menjalankan, menguji, dan men-deploy workload.
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
Enable the Service Usage API, if it is not already enabled.
Roles required to enable APIs
To enable APIs, you need the
serviceusage.services.enablepermission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). Learn how to grant roles.-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
Enable the Service Usage API, if it is not already enabled.
Roles required to enable APIs
To enable APIs, you need the
serviceusage.services.enablepermission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). Learn how to grant roles.- Pastikan akun pengguna Anda telah diberi peran Service Usage Admin.
Menguji dengan curl
Tetapkan variabel lingkungan
PROJECT_IDdengan ID project Anda:PROJECT_ID=PROJECT_IDGanti PROJECT_ID dengan nomor atau project ID Google Cloud Anda.
Pastikan Anda login ke 'gcloud':
gcloud auth loginCantumkan API dan layanan yang diaktifkan dalam project ini:
curl -H "Authorization: Bearer $(gcloud auth print-access-token)" "https://serviceusage.googleapis.com/v1/projects/${PROJECT_ID}/services?filter=state:ENABLED&fields=services.config.title,services.config.name"Jika Anda melihat output seperti ini, berarti penyiapan Anda berhasil:
{ "services": [ { "config": { "name": "bigquery.googleapis.com", "title": "BigQuery API" } }, { "config": { "name": "bigquerystorage.googleapis.com", "title": "BigQuery Storage API" } }, ...
Langkah berikutnya
Untuk mencantumkan API dan layanan yang diaktifkan atau tersedia di projectGoogle Cloud Anda, lihat Mencantumkan layanan.