Korzystanie z kont usługi OAuth 2.0 z interfejsem Manufacturer Center API

Konta usługi to specjalne konta Google, których aplikacje mogą używać do uzyskania programowego dostępu do interfejsów API Google przez OAuth 2.0. Konto usługi używa procesu OAuth 2.0, który nie wymaga dodatkowej autoryzacji. Zamiast tego korzysta z pliku klucza, do którego dostęp ma tylko Twoja aplikacja. Z tego przewodnika dowiesz się, jak uzyskać dostęp do interfejsu Manufacturer Center API za pomocą kont usługi.

Wymagania wstępne

Uzyskiwanie dostępu do interfejsu Manufacturer Center API za pomocą konta usługi

  1. Wygeneruj dane logowania do konta usługi lub uzyskaj dostęp do publicznych danych logowania, które zostały już wygenerowane. Musisz utworzyć identyfikator klienta OAuth 2.0 i uzyskać plik klucza *.json:

    1. Otwórz konsolę interfejsów API Google.

    2. Wybierz projekt w menu u góry strony. Jeśli jeszcze go nie masz, kliknij Utwórz projekt, aby go utworzyć.

    3. Jeśli interfejs Manufacturer Center API nie jest jeszcze włączony w tym projekcie, wyszukaj go na liście interfejsów API Google i włącz.

    4. Na pasku bocznym po lewej stronie wybierz Dane logowania.

    5. Aby skonfigurować konto usługi, wybierz Utwórz dane logowania, a następnie Klucz konta usługi. ![Utwórz dane logowania na konto usługi

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

zrzut ekranu.](../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. Dodaj nowe konto usługi jako użytkownika do konta Manufacturer Center. Jeśli jesteś deweloperem zewnętrznym, musisz poprosić swojego klienta o wykonanie tych czynności.

    1. Otwórz konto Manufacturer Center.

    2. Otwórz listę „Użytkownicy” w ustawieniach konta Manufacturer Center.

    3. Kliknij przycisk +Użytkownik i użyj identyfikatora konta usługi jako adresu e-mail nowego użytkownika. ![Przycisk dodawania konta użytkownika usługi

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

zrzut ekranu.](../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. Teraz możesz uzyskać dostęp do konta Manufacturer Center za pomocą konta usługi, korzystając z procedury domyślne dane logowania aplikacji Google lub bezpośrednio z procesu konta usługi. Przykłady interfejsu Manufacturer Center API pokazują, jak używać obu procesów do danych logowania na konto usługi w każdym obsługiwanym języku programowania. Zapoznaj się z przykładowym kodem, aby wypróbować nowe konto usługi i dowiedzieć się, jakie zmiany będą potrzebne w przypadku używania kont usługi we własnym kodzie.

Najczęstsze pytania

Czy mogę zalogować się w interfejsie internetowym Manufacturer Center za pomocą konta usługi?

Nie. Konta usługi nie są standardowymi kontami Google i nie można uzyskać dostępu do interfejsu internetowego Manufacturer Center.

Jak często należy odświeżać tokeny dostępu do konta usługi?

Tokeny dostępu wygasają w ciągu godziny od wysłania ich przez serwer autoryzacji Google OAuth 2.0. Gdy token dostępu wygaśnie, aplikacja powinna użyć biblioteki klienta do pobrania kolejnego tokena dostępu.