Manufacturer Center API के साथ, OAuth 2.0 सेवा खातों का इस्तेमाल करना

सेवा खाते, खास Google खाते हैं. इनका इस्तेमाल उन ऐप्लिकेशन के लिए किया जा सकता है जो OAuth 2.0 के ज़रिए, Google API को प्रोग्राम के हिसाब से ऐक्सेस कर सकते हैं. सेवा खाता, OAuth 2.0 फ़्लो का इस्तेमाल करता है. इसके लिए, अतिरिक्त अनुमति की ज़रूरत नहीं होती है. इसके बजाय, वह ऐसी कुंजी फ़ाइल का इस्तेमाल करती है जिसे सिर्फ़ आपका ऐप्लिकेशन ऐक्सेस कर सकता है. इस गाइड में, Manufacturer Center API को सेवा खातों से ऐक्सेस करने का तरीका बताया गया है.

ज़रूरी शर्तें

Manufacturer Center API ऐक्सेस करने के लिए किसी सेवा खाते का इस्तेमाल करने का तरीका

  1. सेवा-खाते के क्रेडेंशियल जनरेट करें या पहले से जनरेट किए गए अपने सार्वजनिक क्रेडेंशियल ऐक्सेस करें. आपको OAuth 2.0 क्लाइंट आईडी बनाकर, एक *.json निजी कुंजी फ़ाइल बनानी होगी:

    1. Google के एपीआई कंसोल पर जाएं.

    2. पेज के सबसे ऊपर दिए गए ड्रॉप-डाउन मेन्यू से कोई प्रोजेक्ट चुनें. अगर आपके पास अब तक कोई प्रोजेक्ट नहीं है, तो प्रोजेक्ट बनाएं पर क्लिक करके, खाता बनाएं.

    3. अगर आपने पहले से ही इस प्रोजेक्ट के लिए Manufacturer Center API चालू नहीं किया है, तो Google API की सूची में उसे खोजें और चालू करें.

    4. बाईं ओर मौजूद साइडबार में, क्रेडेंशियल चुनें.

    5. सेवा खाता सेट अप करने के लिए, क्रेडेंशियल बनाएं चुनें. इसके बाद, सेवा खाते की कुंजी चुनें. ![सेवा खाते के क्रेडेंशियल बनाना

स्क्रीनशॉट.](../images/create_service_account_क्रेडेंशियल.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. अब आप या तो Google ऐप्लिकेशन के डिफ़ॉल्ट क्रेडेंशियल फ़्लो का इस्तेमाल करके या सीधे सेवा खाते के फ़्लो का इस्तेमाल करके, सेवा खाते का इस्तेमाल करके अपना Manufacturer Center खाता ऐक्सेस कर सकते हैं. Manufacturer Center API के नमूने बताए गए हैं कि कार्यक्रम की सुविधा देने वाली हर भाषा में, सेवा खाते के क्रेडेंशियल के लिए दोनों फ़्लो का इस्तेमाल कैसे किया जाता है. अपने नए सेवा खाते को आज़माने के लिए, कोड के नमूने देखें. साथ ही, यह जानें कि अपने कोड में, सेवा खातों का इस्तेमाल करने के लिए आपको किन बदलावों की ज़रूरत होगी.

अक्सर पूछे जाने वाले सवाल

क्या अपने Manufacturer Center खाते से, Manufacturer Center के वेब यूज़र इंटरफ़ेस में लॉग इन किया जा सकता है?

नहीं, सेवा खाते नियमित Google खाते नहीं हैं और वे Manufacturer Center के वेब यूज़र इंटरफ़ेस को ऐक्सेस नहीं कर सकते.

मुझे सेवा खाते के ऐक्सेस टोकन को कितनी बार रीफ़्रेश करना होगा?

Google, OAuth 2.0 का ऑथराइज़ेशन सर्वर जारी करने के एक घंटे बाद, ऐक्सेस टोकन की समयसीमा खत्म हो जाती है. जब किसी ऐक्सेस टोकन की समयसीमा खत्म हो जाती है, तो ऐप्लिकेशन को कोई दूसरा ऐक्सेस टोकन पाने के लिए क्लाइंट लाइब्रेरी का इस्तेमाल करना चाहिए.