שימוש בחשבונות שירות OAuth 2.0 עם Manufacturer Center API

חשבונות שירות הם חשבונות Google מיוחדים שבהם אפליקציות יכולות להשתמש כדי לגשת אל Google APIs באופן פרוגרמטי דרך OAuth 2.0. בחשבון שירות נעשה שימוש בתהליך OAuth 2.0 שלא מחייב הרשאה נוספת. במקום זאת, היא משתמשת בקובץ מפתח שרק לאפליקציה שלכם יש גישה אליו. המדריך הזה מסביר איך לגשת ל-Manufacturer Center API באמצעות חשבונות שירות.

דרישות מוקדמות

איך משתמשים בחשבון שירות כדי לגשת ל-Manufacturer Center API

  1. תוכלו ליצור פרטי כניסה של חשבון שירות או לגשת לפרטי הכניסה הציבוריים שכבר הפקתם. תצטרכו ליצור מזהה לקוח ב-OAuth 2.0 ולקבל קובץ מפתח פרטי מסוג .json:

    1. נכנסים למסוף Google API.

    2. בוחרים פרויקט בתפריט הנפתח שבחלק העליון של הדף. אם עדיין אין לכם פרויקט, לוחצים על Create Project.

    3. אם לא הפעלתם כבר את Manufacturer Center API בפרויקט הזה, חפשו אותו ברשימת ממשקי ה-API של Google והפעילו אותו.

    4. בסרגל הצד שמימין, בוחרים באפשרות פרטי כניסה.

    5. כדי להגדיר חשבון שירות, לוחצים על Create credentials ואז על Service account key. ![יצירה של פרטי כניסה לחשבון שירות

צילום מסך.](../images/create_service_account_credentials.png)

6.  On the next page, select **New service account** from the drop-down
    list.

7.  <a name="service-account-name"></a> Name the new service account. This
    also serves as the default username for the service account ID. Remember
the service account ID for use later.

Note: The choice of role for the service account will not have any effect on
what calls can be made to the Manufacturer Center API, as access to
    Manufacturer Center API methods is determined instead by the role
    associated with the service account ID in Manufacturer Center. If you
    are unsure what to pick, just pick Project►Viewer.

![New service account name

צילום מסך.](../images/new_service_account_name.png)

8.  Select **JSON** for the key type, then click **Create**.

9.  The **Create** button will change to **Creating...**, and once the key
    generation finishes, it will automatically download the private key as a
*.json file.

Important: Protect the *.json key file that allows a service account to
    access the Google services for which it has been authorized. It is good
practice to allow service accounts to only access one Google API each. This
is a preventative measure to mitigate the amount of data an attacker can
    access in the situation that the service account's *.json key file is
    compromised.

10.  You will be returned to the Credentials page, and you should see the
    new service account in the list of service account keys for your
    account.
  1. מוסיפים את חשבון השירות החדש כמשתמש לחשבון Manufacturer Center שלכם. אם אתם מפתחים מצד שלישי, הלקוח שלכם יצטרך לבצע את השלב הזה עבורכם.

    1. נכנסים לחשבון Manufacturer Center.

    2. נכנסים לקטע 'Users' בהגדרות של חשבון Manufacturer Center.

    3. לוחצים על הלחצן +User ומשתמשים בכתובת האימייל של המשתמש החדש כמספר חשבון השירות. ![לחצן הוספת משתמש בחשבון השירות

צילום מסך.](../images/add_service_account_network_settings.png)

4.  Fill in the form with the [service account ID](#service-account-name),
    and select the desired user role(s). At least one must be chosen, and
    use of the `Accounts` service requires the Admin role.

If you did not take note of the service account ID earlier, go to the
    [Service
    Accounts](https://console.developers.google.com/iam-admin/serviceaccounts/)
administration page and select the project you created.

![Add service account user page

צילום מסך.](../images/add_service_account_page.png)

5.  Click on the **Save** button. You will be returned to the list of users,
and the service account ID should be listed with the chosen user role(s).

6.  Repeat the process for all other service accounts you want to add.

7.  View existing service account users by going to the Users tab. These
    will be users with an email address ending in 'gserviceaccount.com'.
  1. עכשיו תוכלו לגשת לחשבון Manufacturer Center דרך חשבון השירות באמצעות פרטי הכניסה של אפליקציית Google המוגדרת כברירת מחדל או על ידי זרימה ישירה של תהליך השירות לחשבון. בדוגמאות של Manufacturer Center API מוסבר איך להשתמש בשני התהליכים של פרטי הכניסה לחשבון השירות בכל שפת תכנות נתמכת. תוכלו לעיין בדוגמאות הקוד כדי לנסות את חשבון השירות החדש שלכם ולראות אילו שינויים תצטרכו להשתמש בחשבונות שירות בקוד שלכם.

שאלות נפוצות

האם אפשר להיכנס לממשק המשתמש של Manufacturer Center באמצעות חשבון השירות שלי?

לא, חשבונות שירות אינם חשבונות Google רגילים ואין להם גישה לממשק המשתמש של Manufacturer Center באינטרנט.

באיזו תדירות צריך לרענן אסימוני גישה לחשבון שירות?

התוקף של אסימוני הגישה פג שעה אחת אחרי שהם מונפקים על ידי שרת ההרשאות של Google OAuth 2.0. כשתוקף אסימון הגישה פג, האפליקציה צריכה להשתמש בספריית הלקוח כדי לאחזר אסימון גישה אחר.