הגדרה של Service Usage בסביבת פיתוח
בדף הזה מוסבר איך להגדיר את סביבת הפיתוח כך שתעבוד עם Service Usage API.
- ברוב התרחישים האופרטיביים לדוגמה, הדרך הפשוטה ביותר להפעיל ולהשבית שירותים היא באמצעות מסוף Google Cloud .
- אם אתם צריכים ליצור סקריפטים, אתם יכולים להשתמש ב-Google Cloud CLI.
- אם אתם צריכים לכתוב קוד שמשתמש ב-Service Usage API, אפשר להשתמש באחת מספריות הלקוח.
- כדי להתנסות ב-API בלי להגדיר סביבת פיתוח מלאה לאפליקציות, תוכלו לבצע את ההוראות החלופיות להגדרה שמפורטות במדריך הזה ולהשתמש בפקודה
curl.
הגדרה לקריאה ישירה ל-API
בקטע הזה מתוארים השלבים הבסיסיים להגדרת הסביבה המקומית שלכם כדי להתנסות ב-Service Usage API באמצעות הפקודה curl. הממשק מיועד למפתחים שצריכים לכתוב קוד שמשתמש ב-Service Usage API.
הפעלת Service Usage API
כדי להשתמש ב-Service Usage API, קודם צריך להפעיל אותו בGoogle Cloud פרויקט.
- נכנסים לחשבון Google Cloud . אם אתם משתמשים חדשים ב- Google Cloud, צרו חשבון כדי שתוכלו להעריך את הביצועים של המוצרים שלנו בתרחישים מהעולם האמיתי. לקוחות חדשים מקבלים בחינם גם קרדיט בשווי 300$ להרצה, לבדיקה ולפריסה של עומסי העבודה.
-
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.
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.
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.- מוודאים שחשבון המשתמש קיבל את התפקיד Service Usage Admin.
בדיקה באמצעות curl
מגדירים משתנה סביבה
PROJECT_IDעם המזהה של הפרויקט:PROJECT_ID=PROJECT_IDמחליפים את PROJECT_ID במזהה או במספר הפרויקט ב- Google Cloud .
מוודאים שאתם מחוברים ל-gcloud:
gcloud auth loginהצגת רשימה של ממשקי ה-API והשירותים המופעלים בפרויקט הזה:
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"אם מופיע פלט כמו זה, סימן שההגדרה הושלמה בלי שגיאות:
{ "services": [ { "config": { "name": "bigquery.googleapis.com", "title": "BigQuery API" } }, { "config": { "name": "bigquerystorage.googleapis.com", "title": "BigQuery Storage API" } }, ...
השלבים הבאים
כדי לראות את רשימת ממשקי ה-API והשירותים שמופעלים או זמינים בפרויקטים שלכם ב-Google Cloud , אפשר לעיין במאמר בנושא רישום שירותים.