הגדרה של 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 פרויקט.

  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.

    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.

    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. מוודאים שחשבון המשתמש קיבל את התפקיד Service Usage Admin.

בדיקה באמצעות 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 , אפשר לעיין במאמר בנושא רישום שירותים.