استخدام حسابات خدمة OAuth 2.0 مع واجهة برمجة تطبيقات Manufacturer Center

حسابات الخدمة هي حسابات Google خاصة يمكن أن تستخدمها التطبيقات للدخول إلى Google APIs برمجيًا عبر OAuth 2.0. يستخدم حساب الخدمة تدفق OAuth 2.0 الذي لا يتطلب مصادقة إضافية. بدلاً من ذلك، يستخدم هذا الملف ملفًا رئيسيًا يمكن لتطبيقك فقط الدخول إليه. يتناول هذا الدليل كيفية الوصول إلى واجهة برمجة تطبيقات Manufacturer Center باستخدام حسابات الخدمة.

المتطلبات الأساسية

خطوات استخدام حساب الخدمة للوصول إلى Manufacturer Center API

  1. يمكنك إنشاء بيانات اعتماد حساب الخدمة أو الوصول إلى بيانات الاعتماد العامة التي أنشأتها من قبل. ستحتاج إلى إنشاء معرّف عميل OAuth 2.0 والحصول على ملف مفتاح خاص *.json:

    1. انتقِل إلى وحدة التحكم في واجهة Google API.

    2. اختَر مشروعًا من القائمة المنسدلة في أعلى الصفحة. إذا لم يكن لديك حساب حتى الآن، فأنشئ واحدًا بالنقر على إنشاء مشروع.

    3. إذا لم يسبق لك تمكين واجهة برمجة تطبيقات Manufacturer Center لهذا المشروع، فابحث عنها في قائمة Google APIs ومكّنها.

    4. في الشريط الجانبي على يمين الصفحة، اختَر بيانات الاعتماد.

    5. لإعداد حساب خدمة، اختَر إنشاء بيانات اعتماد، ثم مفتاح حساب الخدمة. ![إنشاء بيانات اعتماد حساب الخدمة

لقطة شاشة.](../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. انتقل إلى قائمة "المستخدمون" في إعدادات حسابك على Manufacturer Center.

    3. انقر على الزر +مستخدم، واستخدم رقم تعريف حساب الخدمة كعنوان البريد الإلكتروني للمستخدم الجديد. ![إضافة زر مستخدم حساب الخدمة

لقطة شاشة.](../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 Application أو باستخدام تدفق حساب الخدمة مباشرةً. توضّح نماذج واجهة برمجة تطبيقات Manufacturer Center كيفية استخدام كلا المسارين لبيانات اعتماد حساب الخدمة في كل لغة برمجة متوافقة. اطلع على نماذج الشفرة لتجربة حساب الخدمة الجديد ولمعرفة التغييرات التي ستحتاج إليها لاستخدام حسابات الخدمة في شفرتك.

الأسئلة الشائعة

هل يمكنني تسجيل الدخول إلى واجهة مستخدم الويب في Manufacturer Center باستخدام حساب الخدمة؟

لا، حسابات الخدمة ليست حسابات عادية على Google ولا يمكنها الوصول إلى واجهة مستخدم الويب في Manufacturer Center.

كم مرة أحتاج إلى تحديث رموز الدخول إلى حساب الخدمة؟

تنتهي صلاحية رموز الدخول المميزة بعد ساعة واحدة من إصدارها بواسطة خادم تفويض Google OAuth 2.0. وعند انتهاء صلاحية رمز دخول، يجب أن يستخدم التطبيق مكتبة العميل لجلب رمز دخول آخر.