استفاده از حسابهای سرویس OAuth 2.0 با Manufacturer Center API
با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
حسابهای سرویس، حسابهای Google ویژهای هستند که میتوانند توسط برنامهها برای دسترسی برنامهنویسی به Google API از طریق OAuth 2.0 استفاده شوند. یک حساب سرویس از یک جریان OAuth 2.0 استفاده می کند که به مجوز اضافی نیاز ندارد. در عوض، از یک فایل کلیدی استفاده می کند که فقط برنامه شما می تواند به آن دسترسی داشته باشد. این راهنما نحوه دسترسی به Manufacturer Center API با حسابهای سرویس را مورد بحث قرار میدهد.
مراحل استفاده از حساب سرویس برای دسترسی به Manufacturer Center API
اعتبارنامههای حساب سرویس ایجاد کنید یا به اعتبارنامههای عمومی که قبلاً ایجاد کردهاید دسترسی پیدا کنید. شما باید یک شناسه مشتری OAuth 2.0 ایجاد کنید و یک فایل کلید خصوصی *.json دریافت کنید:
یک پروژه را در منوی کشویی در بالای صفحه انتخاب کنید. اگر هنوز یکی را ندارید، با کلیک روی ایجاد پروژه، یکی را ایجاد کنید.
اگر قبلاً Manufacturer Center API را برای این پروژه فعال نکردهاید، آن را در فهرست APIهای Google جستجو کرده و آن را فعال کنید.
در نوار کناری سمت چپ، اعتبارنامه ها را انتخاب کنید.
برای تنظیم یک حساب سرویس، Create credentials و سپس Service key account account را انتخاب کنید.
در صفحه بعد، حساب کاربری جدید را از لیست کشویی انتخاب کنید.
حساب سرویس جدید را نام ببرید. این همچنین به عنوان نام کاربری پیشفرض برای شناسه حساب سرویس عمل میکند. شناسه حساب سرویس را برای استفاده در آینده به خاطر بسپارید.
JSON را برای نوع کلید انتخاب کنید، سپس روی ایجاد کلیک کنید.
دکمه Create به Creating... تغییر می کند و پس از اتمام تولید کلید، به طور خودکار کلید خصوصی را به عنوان یک فایل *.json دانلود می کند.
شما به صفحه اعتبارنامه بازگردانده می شوید و باید حساب سرویس جدید را در لیست کلیدهای حساب سرویس برای حساب خود مشاهده کنید.
حساب سرویس جدید را به عنوان کاربر به حساب Manufacturer Center خود اضافه کنید. اگر شما یک توسعه دهنده شخص ثالث هستید، باید از مشتری خود بخواهید این مرحله را برای شما انجام دهد.
در تنظیمات حساب Manufacturer Center خود به لیست «کاربران» بروید.
روی دکمه +User کلیک کنید و از شناسه حساب سرویس به عنوان آدرس ایمیل کاربر جدید استفاده کنید.
فرم را با شناسه حساب سرویس پر کنید و نقش(های) کاربر مورد نظر را انتخاب کنید. حداقل یکی باید انتخاب شود و استفاده از سرویس Accounts به نقش مدیر نیاز دارد.
اگر قبلاً شناسه حساب سرویس را یادداشت نکردهاید، به صفحه مدیریت حسابهای سرویس بروید و پروژهای را که ایجاد کردهاید انتخاب کنید.
بر روی دکمه ذخیره کلیک کنید. شما به لیست کاربران بازگردانده میشوید و شناسه حساب سرویس باید با نقش(های) کاربر انتخابی فهرست شود.
این فرآیند را برای همه حسابهای سرویس دیگری که میخواهید اضافه کنید، تکرار کنید.
با رفتن به تب کاربران، کاربران حساب های سرویس موجود را مشاهده کنید. اینها کاربرانی خواهند بود که آدرس ایمیلشان به «gserviceaccount.com» ختم میشود.
اکنون میتوانید با استفاده از جریان اعتبارنامه پیشفرض Google Application یا با استفاده مستقیم از جریان حساب سرویس، به حساب Manufacturer Center خود با استفاده از حساب سرویس دسترسی پیدا کنید. نمونه های Manufacturer Center API نشان می دهد که چگونه از هر دو جریان برای اعتبار حساب سرویس در هر زبان برنامه نویسی پشتیبانی شده استفاده کنید. نمونههای کد را ببینید تا حساب سرویس جدید خود را امتحان کنید و بدانید که برای استفاده از حسابهای سرویس در کد خود به چه تغییراتی نیاز دارید.
سوالات متداول
آیا می توانم با حساب سرویس خود وارد رابط کاربری وب Manufacturer Center شوم؟
خیر، حسابهای سرویس، حسابهای Google معمولی نیستند و نمیتوانند به رابط کاربری وب Manufacturer Center دسترسی داشته باشند.
هر چند وقت یکبار باید نشانههای دسترسی به حساب سرویس را بازخوانی کنم؟
توکنهای دسترسی یک ساعت پس از صدور توسط سرور مجوز Google OAuth 2.0 منقضی میشوند. هنگامی که یک نشانه دسترسی منقضی می شود، برنامه باید از کتابخانه مشتری برای واکشی نشانه دسترسی دیگری استفاده کند.
تاریخ آخرین بهروزرسانی 2025-08-29 بهوقت ساعت هماهنگ جهانی.
[null,null,["تاریخ آخرین بهروزرسانی 2025-08-29 بهوقت ساعت هماهنگ جهانی."],[[["\u003cp\u003eService accounts enable applications to programmatically access the Manufacturer Center API using OAuth 2.0 without user intervention.\u003c/p\u003e\n"],["\u003cp\u003eTo use a service account, generate service account credentials in Google Cloud Console, enable the Manufacturer Center API, and download the JSON key file.\u003c/p\u003e\n"],["\u003cp\u003eAdd the service account as a user to your Manufacturer Center account with the appropriate role for API access.\u003c/p\u003e\n"],["\u003cp\u003eAccess your Manufacturer Center account programmatically using Google Application Default Credentials or the service account flow, referencing the provided samples.\u003c/p\u003e\n"],["\u003cp\u003eService accounts cannot be used to log into the Manufacturer Center web user interface but solely for API interaction.\u003c/p\u003e\n"]]],[],null,["# Using OAuth 2.0 service accounts with the Manufacturer Center API\n\nService accounts are special Google accounts that can be used by applications to\naccess Google APIs programmatically via OAuth 2.0. A service account uses an\nOAuth 2.0 flow that does not require additional authorization. Instead, it uses\na key file that only your application can access. This guide discusses how to\naccess the Manufacturer Center API with service accounts.\n| **Note:** Applications using service accounts for authentication can only access your own Manufacturer Center account. If you are writing a third-party application that needs access to your clients' Manufacturer Center accounts, see the [Authorizing Requests](/manufacturers/how-tos/authorizing) guide instead.\n\nPrerequisites\n-------------\n\n- A [Manufacturer Center](//manufacturers.google.com/) account.\n\nSteps to using a service account to access the Manufacturer Center API\n----------------------------------------------------------------------\n\n1. Generate service-account credentials or access the public credentials you've\n already generated. You will need to create an OAuth 2.0 Client ID and obtain\n a \\*.json private key file:\n\n 1. Go to the [Google API Console](https://console.cloud.google.com/apis/library).\n\n 2. Select a project in the drop-down menu at the top of the page. If you do\n not have one yet, create one by clicking **Create Project**.\n\n 3. If you have not already enabled the Manufacturer Center API for this\n project, then search for it in the list of Google APIs and enable it.\n\n 4. In the sidebar on the left, select **Credentials**.\n\n 5. To set up a service account, select **Create credentials** , and then\n **Service account key**.\n\n 1. On the next page, select **New service account** from the drop-down\n list.\n\n 2. Name the new service account. This\n also serves as the default username for the service account ID. Remember\n the service account ID for use later.\n\n | **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.\n\n 1. Select **JSON** for the key type, then click **Create**.\n\n 2. The **Create** button will change to **Creating...**, and once the key\n generation finishes, it will automatically download the private key as a\n \\*.json file.\n\n | **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.\n 1. 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.\n2. Add the new service account as a user to your Manufacturer Center account.\n If you are a third party developer, you will need to have your client do\n this step for you.\n\n 1. Go to your [Manufacturer Center account](//manufacturers.google.com/).\n\n 2. Go to the 'Users' list in the settings of your Manufacturer Center\n account.\n\n 3. Click the +User button, and use the service account ID as the email\n address for the new user.\n\n 4. Fill in the form with the [service account ID](#service-account-name),\n and select the desired user role(s). At least one must be chosen, and\n use of the `Accounts` service requires the Admin role.\n\n If you did not take note of the service account ID earlier, go to the\n [Service Accounts](https://console.developers.google.com/iam-admin/serviceaccounts/)\n administration page and select the project you created.\n\n 1. Click on the **Save** button. You will be returned to the list of users,\n and the service account ID should be listed with the chosen user role(s).\n\n 2. Repeat the process for all other service accounts you want to add.\n\n 3. View existing service account users by going to the Users tab. These\n will be users with an email address ending in 'gserviceaccount.com'.\n\n3. Now you can access your Manufacturer Center account using the service\n account either by using the [Google Application Default\n Credentials](/identity/protocols/application-default-credentials) flow or by\n using the [service account flow](/identity/protocols/OAuth2ServiceAccount)\n directly. The Manufacturer Center API [Samples](/manufacturers/libraries)\n show how to use both flows for service account credentials in each supported\n programming language. See the code samples to try out your new service\n account and to learn what changes you will need to use service accounts in\n your own code.\n\nFrequently asked questions\n--------------------------\n\n#### Can I log into the Manufacturer Center web user interface with my service account?\n\nNo, service accounts are not regular Google accounts and cannot access the\nManufacturer Center web user interface.\n\n#### How often do I need to refresh service account access tokens?\n\nAccess tokens expire one hour after they are issued by the Google OAuth 2.0\nAuthorization Server. When an access token expires, the application should use\nthe client library to fetch another access token."]]