Menggunakan akun layanan OAuth 2.0 dengan Manufacturer Center API

Akun layanan adalah Akun Google khusus yang dapat digunakan oleh aplikasi untuk mengakses Google API secara terprogram melalui OAuth 2.0. Akun layanan menggunakan alur OAuth 2.0 yang tidak memerlukan otorisasi tambahan. Sebagai gantinya, aplikasi ini menggunakan file kunci yang hanya dapat diakses oleh aplikasi Anda. Panduan ini membahas cara mengakses Manufacturer Center API dengan akun layanan.

Prasyarat

Langkah-langkah untuk menggunakan akun layanan untuk mengakses Manufacturer Center API

  1. Buat kredensial akun layanan atau akses kredensial publik yang sudah Anda buat. Anda harus membuat Client ID OAuth 2.0 dan memperoleh file kunci pribadi *.json:

    1. Buka Konsol Google API.

    2. Pilih project di menu drop-down di bagian atas halaman. Jika Anda belum memilikinya, buat project dengan mengklik Create Project.

    3. Jika Anda belum mengaktifkan Manufacturer Center API untuk project ini, telusuri API tersebut dalam daftar Google API dan aktifkan.

    4. Pada sidebar di sebelah kiri, pilih Credentials.

    5. Untuk menyiapkan akun layanan, pilih Create credentials, lalu Service account key. "+Membuat kredensial akun layanan

screenshot.](../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

screenshot.](../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. Tambahkan akun layanan baru sebagai pengguna ke akun Manufacturer Center Anda. Jika Anda adalah developer pihak ketiga, Anda harus meminta klien melakukan langkah ini untuk Anda.

    1. Buka akun Manufacturer Center.

    2. Buka daftar 'Pengguna' di setelan akun Manufacturer Center Anda.

    3. Klik tombol +Pengguna, dan gunakan ID akun layanan sebagai alamat email untuk pengguna baru. "+Tombol pengguna akun layanan ditambahkan

screenshot.](../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

screenshot.](../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. Sekarang, Anda dapat mengakses akun Manufacturer Center menggunakan akun layanan menggunakan alur Kredensial Default Aplikasi Google atau menggunakan alur akun layanan secara langsung. Contoh Manufacturer Center API menunjukkan cara menggunakan kedua alur untuk kredensial akun layanan dalam setiap bahasa pemrograman yang didukung. Lihat contoh kode untuk mencoba akun layanan baru dan mempelajari perubahan yang perlu dilakukan menggunakan akun layanan dalam kode Anda sendiri.

Pertanyaan umum (FAQ)

Dapatkah saya login ke antarmuka pengguna web Manufacturer Center dengan akun layanan saya?

Tidak, akun layanan bukan Akun Google reguler dan tidak dapat mengakses antarmuka pengguna web Manufacturer Center.

Seberapa sering saya perlu memperbarui token akses akun layanan?

Masa berlaku token akses berakhir satu jam setelah dikeluarkan oleh Server Otorisasi Google OAuth 2.0. Saat masa berlaku token akses berakhir, aplikasi harus menggunakan library klien untuk mengambil token akses lain.