הגדרת השימוש בשירות בסביבת פיתוח

באמצעות Service Usage API אפשר לנהל ממשקי API ושירותים בפרויקט ב-Google Cloud . במדריך למתחילים הזה תגדירו את סביבת הפיתוח כך שתתקשר עם 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 .

  1. נכנסים לחשבון Google Cloud . אנחנו ממליצים למשתמשים חדשים ב- Google Cloudליצור חשבון כדי שיוכלו להעריך את הביצועים של המוצרים שלנו בתרחישים מהעולם האמיתי. לקוחות חדשים מקבלים בחינם גם קרדיט בשווי 300$ להרצה, לבדיקה ולפריסה של עומסי העבודה.
  2. 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 the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  3. Enable the Service Usage API, if it is not already enabled.

    Roles required to enable APIs

    To enable APIs, you need the serviceusage.services.enable permission. 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.

    Enable the API

  4. 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 the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  5. Enable the Service Usage API, if it is not already enabled.

    Roles required to enable APIs

    To enable APIs, you need the serviceusage.services.enable permission. 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.

    Enable the API

  6. מוודאים שלחשבון המשתמש שלכם הוקצה התפקיד אדמין של שימוש בשירות.

בדיקה באמצעות curl

  1. מגדירים משתנה סביבה PROJECT_ID עם מזהה הפרויקט:

    PROJECT_ID=PROJECT_ID
    

    מחליפים את PROJECT_ID במספר או במזהה הפרויקט ב- Google Cloud .

  2. מוודאים שאתם מחוברים ל-gcloud:

    gcloud auth login
    
  3. מציגים את ממשקי ה-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 , קראו את המאמר הצגת רשימת השירותים.