בדף הזה מוסבר איך להשתמש במפתחות API כדי לגשת ל-API ולשירותים שמקבלים מפתחות API. Google Cloud
לא כל ממשקי ה-API מקבלים מפתחות API לצורך אישור השימוש. Google Cloud כדי לדעת אם מוצעת תמיכה למפתחות API, מומלץ לעיין במאמרי העזרה של השירות או של ה-API.
מידע על יצירה וניהול של מפתחות API, כולל הגבלת מפתחות API, זמין במאמר ניהול מפתחות API.
מידע על השימוש במפתחות API בפלטפורמה של מפות Google זמין במאמרי העזרה של הפלטפורמה של מפות Google. מידע נוסף על API Keys API זמין במאמרי העזרה של ה-API של API Keys.לפני שמתחילים
Select the tab for how you plan to use the samples on this page:
C#
כדי להשתמש בסביבת פיתוח מקומית בדוגמאות של .NET שבדף הזה, מתקינים ומפעילים את ה-CLI של gcloud, ואז מגדירים את Application Default Credentials באמצעות פרטי הכניסה של המשתמש.
-
Install the Google Cloud CLI.
-
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
-
If you're using a local shell, then create local authentication credentials for your user account:
gcloud auth application-default login
You don't need to do this if you're using Cloud Shell.
If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.
למידע נוסף, ראו הגדרת ADC לסביבת פיתוח מקומית במאמרי העזרה בנושא אימות Google Cloud .
C++
כדי להשתמש בסביבת פיתוח מקומית בדוגמאות של C++ שבדף הזה, מתקינים ומפעילים את ה-CLI של gcloud, ואז מגדירים את Application Default Credentials באמצעות פרטי הכניסה של המשתמש.
-
Install the Google Cloud CLI.
-
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
-
If you're using a local shell, then create local authentication credentials for your user account:
gcloud auth application-default login
You don't need to do this if you're using Cloud Shell.
If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.
למידע נוסף, ראו הגדרת ADC לסביבת פיתוח מקומית במאמרי העזרה בנושא אימות Google Cloud .
Go
כדי להשתמש בסביבת פיתוח מקומית בדוגמאות של Go שבדף הזה, מתקינים ומפעילים את ה-CLI של gcloud, ואז מגדירים את Application Default Credentials באמצעות פרטי הכניסה של המשתמש.
-
Install the Google Cloud CLI.
-
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
-
If you're using a local shell, then create local authentication credentials for your user account:
gcloud auth application-default login
You don't need to do this if you're using Cloud Shell.
If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.
למידע נוסף, ראו הגדרת ADC לסביבת פיתוח מקומית במאמרי העזרה בנושא אימות Google Cloud .
Node.js
כדי להשתמש בסביבת פיתוח מקומית בדוגמאות של Node.js שבדף הזה, מתקינים ומפעילים את ה-CLI של gcloud, ואז מגדירים את Application Default Credentials באמצעות פרטי הכניסה של המשתמש.
-
Install the Google Cloud CLI.
-
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
-
If you're using a local shell, then create local authentication credentials for your user account:
gcloud auth application-default login
You don't need to do this if you're using Cloud Shell.
If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.
למידע נוסף, ראו הגדרת ADC לסביבת פיתוח מקומית במאמרי העזרה בנושא אימות Google Cloud .
Python
כדי להשתמש בסביבת פיתוח מקומית בדוגמאות של Python שבדף הזה, מתקינים ומפעילים את ה-CLI של gcloud, ואז מגדירים את Application Default Credentials באמצעות פרטי הכניסה של המשתמש.
-
Install the Google Cloud CLI.
-
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
-
If you're using a local shell, then create local authentication credentials for your user account:
gcloud auth application-default login
You don't need to do this if you're using Cloud Shell.
If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.
למידע נוסף, ראו הגדרת ADC לסביבת פיתוח מקומית במאמרי העזרה בנושא אימות Google Cloud .
REST
כדי להשתמש בדוגמאות של API בארכיטקטורת REST שבדף הזה בסביבת פיתוח מקומית, צריך להשתמש בפרטי הכניסה שאתם נותנים ל-CLI של gcloud.
Install the Google Cloud CLI.
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
מידע נוסף מופיע במאמר אימות לשימוש ב-REST במסמכי האימות של Google Cloud .
שימוש במפתח API באמצעות REST
כדי לכלול מפתח API בקריאה ל-API בארכיטקטורת REST, משתמשים בכותרת ה-HTTP x-goog-api-key, כמו בדוגמה הבאה:
curl -X POST \
-H "X-goog-api-key: API_KEY" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://translation.googleapis.com/language/translate/v2"
אם אי אפשר להשתמש בכותרת HTTP, אפשר להשתמש בפרמטר השאילתה key.
עם זאת, השיטה הזו כוללת את מפתח ה-API בכתובת ה-URL, ולכן המפתח חשוף לגניבה באמצעות סריקות של כתובות URL.
בדוגמה הבאה מוצג אופן השימוש בפרמטר השאילתה key עם בקשת API של Cloud Natural Language עבור documents.analyzeEntities.
מחליפים את הערך API_KEY במחרוזת המפתח של מפתח ה-API.
POST https://language.googleapis.com/v1/documents:analyzeEntities?key=API_KEY
שימוש במפתח API באמצעות ספריות לקוח
כדי להדגים איך מספקים מפתח API לספרייה, בדוגמה הזו נשתמש ב-Cloud Natural Language API שתומך במפתחות API.
C#
כדי להריץ את הדוגמה הזו, צריך להתקין את ספריית הלקוח של שפה טבעית.
C++
כדי להריץ את הדוגמה הזו, צריך להתקין את ספריית הלקוח של שפה טבעית.
Go
כדי להריץ את הדוגמה הזו, צריך להתקין את ספריית הלקוח של שפה טבעית.
Node.js
כדי להריץ את הדוגמה הזו, צריך להתקין את ספריית הלקוח של שפה טבעית.
Python
כדי להריץ את הדוגמה הזו, צריך להתקין את ספריית הלקוח של שפה טבעית.
Ruby
כדי להריץ את הדוגמה הזו, צריך להתקין את ספריית הלקוח של שפה טבעית.
בזמן השימוש במפתחות API באפליקציות שלכם, צריך לוודא שהן מאובטחות במהלך האחסון ובמהלך ההעברה. חשיפת מפתחות ה-API באופן ציבורי עלולה לגרום לחיובים לא צפויים בחשבון שלכם. מידע נוסף זמין במאמר שיטות מומלצות לניהול מפתחות API.
המאמרים הבאים
אלא אם צוין אחרת, התוכן של דף זה הוא ברישיון Creative Commons Attribution 4.0 ודוגמאות הקוד הן ברישיון Apache 2.0. לפרטים, ניתן לעיין במדיניות האתר Google Developers. Java הוא סימן מסחרי רשום של חברת Oracle ו/או של השותפים העצמאיים שלה.
עדכון אחרון: 2026-03-04 (שעון UTC).