การใช้บัญชีบริการ OAuth 2.0 กับ Manufacturer Center API

บัญชีบริการคือบัญชีพิเศษของ Google ที่แอปพลิเคชันใช้ได้เพื่อเข้าถึง Google API แบบเป็นโปรแกรมผ่าน OAuth 2.0 บัญชีบริการใช้ขั้นตอน OAuth 2.0 ที่ไม่จําเป็นต้องมีการให้สิทธิ์เพิ่มเติม แต่จะใช้ไฟล์คีย์ที่แอปพลิเคชันของคุณเข้าถึงได้เท่านั้น คู่มือนี้จะพูดถึงวิธีเข้าถึง Manufacturer Center API ด้วยบัญชีบริการ

สิ่งที่ต้องดำเนินการก่อน

ขั้นตอนการใช้บัญชีบริการเพื่อเข้าถึง Manufacturer Center API

  1. สร้างข้อมูลเข้าสู่ระบบบัญชีบริการ หรือเข้าถึงข้อมูลเข้าสู่ระบบสาธารณะที่สร้างไว้แล้ว คุณจะต้องสร้างรหัสไคลเอ็นต์ OAuth 2.0 และรับไฟล์คีย์ส่วนตัว * *.json ดังนี้

    1. ไปที่คอนโซล Google API

    2. เลือกโปรเจ็กต์ในเมนูแบบเลื่อนลงที่ด้านบนของหน้า หากยังไม่มี ให้สร้างคลิกสร้างโปรเจ็กต์

    3. หากคุณยังไม่ได้เปิดใช้ Manufacturer Center API สําหรับโปรเจ็กต์นี้ ให้ค้นหา API ดังกล่าวในรายการ Google API และเปิดใช้

    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 หรือโดยใช้โฟลว์บัญชีบริการโดยตรง ตัวอย่าง Manufacturer Center API จะแสดงวิธีใช้ทั้ง 2 ขั้นตอนสําหรับข้อมูลเข้าสู่ระบบของบัญชีบริการในภาษาโปรแกรมที่รองรับแต่ละภาษา ดูตัวอย่างโค้ดเพื่อลองใช้บัญชีบริการใหม่ และดูว่าคุณต้องเปลี่ยนแปลงบัญชีบริการใดบ้างในโค้ดของคุณเอง

คำถามที่พบบ่อย

ฉันจะลงชื่อเข้าสู่ระบบอินเทอร์เฟซผู้ใช้ในเว็บของ Manufacturer Center ด้วยบัญชีบริการของฉันได้ไหม

ไม่ บัญชีบริการไม่ใช่บัญชี Google ปกติและเข้าถึงอินเทอร์เฟซผู้ใช้ในเว็บของ Manufacturer Center ไม่ได้

ฉันต้องรีเฟรชโทเค็นเพื่อการเข้าถึงบัญชีบริการบ่อยเพียงใด

โทเค็นเพื่อการเข้าถึงจะหมดอายุใน 1 ชั่วโมงหลังจากที่ออกโดยเซิร์ฟเวอร์การให้สิทธิ์ของ Google OAuth 2.0 เมื่อโทเค็นเพื่อการเข้าถึงหมดอายุ แอปพลิเคชันควรใช้ไลบรารีของไคลเอ็นต์เพื่อเรียกโทเค็นเพื่อการเข้าถึงอื่น