Authentication
تنظيم صفحاتك في مجموعات
يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
يوضِّح هذا المستند كيفية المصادقة على واجهة برمجة تطبيقات "مدير الإعلانات". تعتمد طريقة مصادقة العميل على الواجهة التي تستخدمها والبيئة التي يتم فيها تنفيذ رمز العميل، ولكن يجب أن تتضمّن جميع طلبات واجهة برمجة التطبيقات رمزًا مميّزًا للوصول مع نطاق Ad Manager API.
تستخدم مكتبات عملاء "مدير الإعلانات" بيانات الاعتماد التلقائية للتطبيق.
لإنشاء رموز الدخول باستخدام نطاق واجهة برمجة تطبيقات "مدير الإعلانات" يعرض هذا الدليل
كيفية ضبط بيانات الاعتماد التلقائية للتطبيق.
إذا لم تكن تستخدم مكتبة برامج، فلا تزال بحاجة إلى إنشاء بيانات اعتماد.
واستخدامها للموافقة على طلباتك.
للحصول على مزيد من المعلومات حول المصادقة والترخيص، يمكنك الاطلاع على
دليل استخدام OAuth 2.0.
تحديد نوع المصادقة
نوع المصادقة |
الوصف |
حساب الخدمة
|
اختَر هذا الخيار إذا كنت تريد المصادقة بصفتك حسابًا مخصّصًا بدلاً من شخص معيّن.
مزيد من المعلومات |
تطبيق الويب
|
اختر هذا الخيار إذا كنت تريد المصادقة كأي مستخدم
الذي يمنح الإذن للتطبيق بالوصول
بيانات "مدير الإعلانات" الخاصة بهم
مزيد من المعلومات |
التطوير المحلي
|
اختَر هذا الخيار إذا كنت تريد المصادقة باستخدام
حسابك على Google أو حساب الخدمة من
بيئة التطوير المحلية. |
تفعيل واجهة برمجة تطبيقات "مدير الإعلانات"
تفعيل واجهة برمجة تطبيقات "مدير الإعلانات" في
مشروع Google API Console على السحابة الإلكترونية.
اختَر مشروعًا أو أنشِئ مشروعًا جديدًا، إذا طُلب منك ذلك.
إنشاء بيانات اعتماد
انقر على علامة التبويب لنوع المصادقة واتّبِع التعليمات ل
إنشاء بيانات الاعتماد:
حساب الخدمة
على Google Cloud
لمصادقة عبء عمل يتم تشغيله على Google Cloud، يمكنك استخدام بيانات اعتماد
حساب الخدمة المرفق بمورد الحوسبة حيث يتم وضع الرمز
الجري.
على سبيل المثال، يمكنك إرفاق حساب خدمة بمثيل جهاز افتراضي (VM) في Compute Engine أو خدمة Cloud Run أو مهمة Dataflow. هذا الأسلوب
هي طريقة المصادقة المفضّلة للرموز البرمجية التي يتم تشغيلها على Google Cloud.
حوسبة الموارد.
للحصول على معلومات عن الموارد التي يمكنك إرفاق حساب خدمة بها، يُرجى اتّباع الخطوات التالية:
والمساعدة في إرفاق حساب الخدمة بالمورد، راجِع
مستندات حول إرفاق حساب الخدمة.
داخل الشركة أو من خلال مقدّم خدمات سحابة إلكترونية مختلف
إنّ الطريقة المفضّلة لإعداد المصادقة من خارج Google Cloud هي
استخدام ميزة اتحاد أعباء العمل إنشاء
ملف تهيئة بيانات الاعتماد وضبط GOOGLE_APPLICATION_CREDENTIALS
متغير البيئة للإشارة إليه. وهذا النهج أكثر أمانًا من
إنشاء مفتاح حساب خدمة
في حال لم تتمكّن من ضبط ميزة إنشاء توافق عبء العمل مع الهوية، عليك
إنشاء حساب خدمة وإنشاء مفتاح لحساب الخدمة:
افتح صفحة بيانات اعتماد وحدة التحكم في Google API.
في صفحة Credentials (بيانات الاعتماد)، اختَر إنشاء بيانات اعتماد، ثم
اختَر حساب الخدمة.
انقر على عنوان البريد الإلكتروني لحساب الخدمة الذي تريد إنشاء
مفتاح له.
انقر على علامة التبويب المفاتيح.
انقر على القائمة المنسدلة إضافة مفتاح، ثم على إنشاء مفتاح جديد.
اختَر JSON كنوع المفتاح وانقر على إنشاء.
اضبط متغيّر البيئة GOOGLE_APPLICATION_CREDENTIALS
على مسارملف JSON.
نظام التشغيل Linux أو macOS
export GOOGLE_APPLICATION_CREDENTIALS=KEY_FILE_PATH
Windows
set GOOGLE_APPLICATION_CREDENTIALS=KEY_FILE_PATH
تطبيق الويب
افتح صفحة بيانات اعتماد وحدة تحكّم واجهة برمجة التطبيقات Google API.
اختَر المشروع الذي فعّلت فيه Ad Manager API، إذا طُلب منك ذلك.
في صفحة "بيانات الاعتماد"، اختَر إنشاء بيانات اعتماد، ثم
اختَر معرِّف عميل OAuth.
اختَر نوع التطبيق تطبيق الويب.
املأ النموذج وانقر على إنشاء. يجب أن تحدِّد التطبيقات التي تستخدم لغات و
أطر عمل مثل PHP وJava وPython وRuby و.NET معرّفات الموارد المنتظمة (URI) المُعتمَدة لإعادة التوجيه. معرّفات الموارد المنتظمة لإعادة التوجيه هي نقاط النهاية التي يمكن لخادم OAuth 2.0 إرسال الردود إليها. يجب أن تتقيّد نقاط النهاية هذه ببنود
قواعد التحقق من الصحة.
بعد إنشاء بيانات الاعتماد، نزِّل ملف client_secret.json. احفظ الملف بأمان في مكان لا يمكن لأحد غير تطبيقك الوصول إليه.
من هنا، اتّبِع الخطوات للحصول على رموز OAuth 2.0 المميّزة للدخول.
تنمية محلية
إعداد بيانات الاعتماد التلقائية للتطبيق (ADC) في البيئة المحلية.
ثبِّت واجهة سطر أوامر Google Cloud، ثم ابدأ إعدادها من خلال تنفيذ الأمر التالي:
gcloud init
أنشئ بيانات اعتماد مصادقة محلية لحسابك على Google واضبط
رقم تعريف المشروع على مشروع تم تفعيل واجهة برمجة التطبيقات "مدير إعلانات Google" فيه:
gcloud auth application-default login --scopes="https://www.googleapis.com/auth/admanager"
gcloud auth application-default set-quota-project PROJECT_ID
بدلاً من ذلك، يمكنك المصادقة كحساب خدمة لضبط البيئة.
المتغير GOOGLE_APPLICATION_CREDENTIALS
إلى مسار ملف المفتاح.
Linux أو macOS
export GOOGLE_APPLICATION_CREDENTIALS=KEY_FILE_PATH
Windows
set GOOGLE_APPLICATION_CREDENTIALS=KEY_FILE_PATH
حساب الخدمة
- انتقِل إلى شبكة "مدير إعلانات Google".
- انقر على علامة التبويب المشرف.
- تأكَّد من تفعيل الوصول إلى واجهة برمجة التطبيقات.
- انقر على الزر إضافة مستخدم حساب الخدمة.
- املأ النموذج باستخدام عنوان البريد الإلكتروني لحساب الخدمة. يجب إضافة
مستخدم حساب الخدمة إلى الأدوار والفِرق المناسبة
لدمج واجهة برمجة التطبيقات.
- انقر على الزر حفظ. يُفترض أن تظهر رسالة تأكيد
إضافة حساب الخدمة.
- يمكنك الاطّلاع على مستخدمي حساب الخدمة الحاليين من خلال الانتقال إلى علامة التبويب "المستخدمون" ثم
النقر على فلتر حساب الخدمة.
تطبيق الويب
- انتقِل إلى شبكة "مدير إعلانات Google".
- انقر على علامة التبويب المشرف.
- تأكَّد من تفعيل الوصول إلى واجهة برمجة التطبيقات.
التنمية المحلية
- انتقِل إلى شبكة "مدير إعلانات Google".
- انقر على علامة التبويب المشرف.
- تأكَّد من تفعيل الوصول إلى واجهة برمجة التطبيقات.
بدون مكتبة عملاء
إذا لم تكن تستخدِم مكتبة عملاء، ننصحك بشدة باستخدام
مكتبة OAuth2 للمصادقة.
للحصول على تعليمات مفصّلة حول الحصول على الرموز المميّزة للوصول، يُرجى الاطّلاع على مقالة
استخدام بروتوكول OAuth2 مع Google APIs.
رموز الدخول
يمكنك تضمين رمز الدخول في طلب إلى واجهة برمجة التطبيقات من خلال تضمين إما
معلَمة طلب البحث access_token
أو قيمة Bearer
لعنوان HTTP يتضمّن Authorization
من الأفضل استخدام رأس HTTP كلما أمكن، لأنّ سلاسل طلبات البحث تميل إلى أن تكون
مرئية في سجلات الخادم.
على سبيل المثال:
GET /v1/networks/1234
Host: admanager.googleapis.com
Authorization: Bearer ya29.a0Ad52N3_shYLX
GET https://admanager.googleapis.com/v1/networks/1234?access_token=1/fFAGRNJru1FTz70BzhT3Zg
النطاق
يرتبط كل رمز دخول بنطاق واحد أو أكثر. يتحكّم النطاق في
مجموعة الموارد والعمليات التي يسمح بها رمز الوصول. مدير الإعلانات
تتضمّن واجهة برمجة التطبيقات نطاقًا واحدًا فقط. يجب تنفيذ التفويض على مستوى
المستخدِم داخل المنتج.
النطاق |
الأذونات |
https://www.googleapis.com/auth/admanager
|
عرض حملاتك وإدارتها
حول "مدير إعلانات Google" |
إنّ محتوى هذه الصفحة مرخّص بموجب ترخيص Creative Commons Attribution 4.0 ما لم يُنصّ على خلاف ذلك، ونماذج الرموز مرخّصة بموجب ترخيص Apache 2.0. للاطّلاع على التفاصيل، يُرجى مراجعة سياسات موقع Google Developers. إنّ Java هي علامة تجارية مسجَّلة لشركة Oracle و/أو شركائها التابعين.
تاريخ التعديل الأخير: 2025-08-31 (حسب التوقيت العالمي المتفَّق عليه)
[null,null,["تاريخ التعديل الأخير: 2025-08-31 (حسب التوقيت العالمي المتفَّق عليه)"],[[["\u003cp\u003eGoogle Ad Manager API authentication depends on the interface and environment but always requires an access token.\u003c/p\u003e\n"],["\u003cp\u003eChoose between service account, web application, or local development authentication based on your needs.\u003c/p\u003e\n"],["\u003cp\u003eEnable the Ad Manager API in your Google API Console and create the necessary credentials for your chosen authentication type.\u003c/p\u003e\n"],["\u003cp\u003eConfigure your Ad Manager network settings and add the service account user or enable API access depending on authentication type.\u003c/p\u003e\n"],["\u003cp\u003eInclude your access token in API requests using either a query parameter or an HTTP header.\u003c/p\u003e\n"]]],["To access the Ad Manager API, you need an access token, generated using Application Default Credentials (ADC) or custom credentials. First, enable the Ad Manager API in your Google Cloud project. Then, choose an authentication type: Service Account, Web application, or Local development. Create credentials via the Google API Console, selecting the appropriate method. If not using a client library, use an OAuth2 library. Finally, include the access token in API requests, preferably in the `Authorization` HTTP header. Each access token should be associated with the `https://www.googleapis.com/auth/admanager` scope.\n"],null,["# Authentication\n\nThis document describes how to authenticate to the Ad Manager API. How you\nauthenticate depends on the interface you use and the environment where your\ncode is running, but all API requests must include an access token with the\nAd Manager API [scope](#scope).\n\nThe Ad Manager client libraries use [Application Default Credentials](//cloud.google.com/docs/authentication/application-default-credentials)\nto generate access tokens with the Ad Manager API scope. This guide shows\nhow to configure Application Default Credentials.\n\nIf you aren't using a client library, you still need to create credentials\nand use them to authorize your requests.\n\nFor more information about authentication and authorization, see the\n[Using OAuth 2.0](/identity/protocols/oauth2) guide.\n\nDetermine your authentication type\n----------------------------------\n\n| Authentication type | Description |\n|---------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| Service Account | Choose this if you want to authenticate as dedicated account rather than a particular person. [Learn more](//cloud.google.com/iam/docs/service-account-overview). |\n| Web application | Choose this if you want to authenticate as any user who grants permission to your application to access their Ad Manager data. [Learn more](/identity/oauth2/web/guides/overview) |\n| Local development | Choose this if you want to authenticate as your own Google Account or a Service Account from your local development environment. |\n\nEnable the Ad Manager API\n-------------------------\n\n1. Enable the [Ad Manager API](https://console.cloud.google.com/apis/library/admanager.googleapis.com) in your\n Google API Console Cloud Project.\n\n2. If prompted, select a project, or create a new one.\n\nCreate credentials\n------------------\n\nClick the tab for your authentication type and follow the instructions to\ncreate your credentials: \n\n### Service Account\n\n### On Google Cloud\n\nTo authenticate a workload running on Google Cloud, you use the credentials of\nthe service account attached to the compute resource where your code is\nrunning.\n\nFor example, you can attach a service account to a Compute Engine virtual\nmachine (VM) instance, a Cloud Run service, or a Dataflow job. This approach\nis the preferred authentication method for code running on a Google Cloud\ncompute resource.\n\nFor information about which resources you can attach a service account to,\nand help with attaching the service account to the resource, see the\n[documentation on attaching a service account](//cloud.google.com/iam/docs/attach-service-accounts).\n\n### On-premises or on a different cloud provider\n\nThe preferred method to set up authentication from outside of Google Cloud is\nto use [workload identity federation](//cloud.google.com/iam/docs/workload-identity-federation); you create a\ncredential configuration file and set the `GOOGLE_APPLICATION_CREDENTIALS`\nenvironment variable to point to it. This approach is more secure than\ncreating a service account key.\n\nIf you are not able to configure workload identity federation, then you must\ncreate a service account and create a key for the service account:\n\n1. Open the [Google API Console Credentials page](https://console.cloud.google.com/apis/credentials).\n\n2. On the Credentials page, select **Create credentials** , then\n select **Service Account**.\n\n3. Click the email address of the service account that you want to create\n a key for.\n\n4. Click the **Keys** tab.\n\n5. Click the **Add key** drop-down menu, then select **Create new key**.\n\n6. Select **JSON** as the **Key type** and click **Create**.\n\n7. Set the environment variable `GOOGLE_APPLICATION_CREDENTIALS` to the path\n of the JSON file.\n\n#### Linux or macOS\n\n export GOOGLE_APPLICATION_CREDENTIALS=\u003cvar label=\"key file\" translate=\"no\"\u003eKEY_FILE_PATH\u003c/var\u003e\n\n#### Windows\n\n set GOOGLE_APPLICATION_CREDENTIALS=\u003cvar label=\"key file\" translate=\"no\"\u003eKEY_FILE_PATH\u003c/var\u003e\n\n### Web application\n\n1. Open the [Google API Console Credentials page](https://console.cloud.google.com/apis/credentials).\n\n2. If prompted, select the project where you enabled the Ad Manager API.\n\n3. On the Credentials page, select **Create credentials** , then\n select **OAuth client ID**.\n\n4. Select the **Web application** application type.\n\n5. Fill in the form and click **Create** . Applications that use languages and\n frameworks like PHP, Java, Python, Ruby, and .NET must specify authorized\n **redirect URIs** . The redirect URIs are the endpoints to which the OAuth 2.0\n server can send responses. These endpoints must adhere to [Google's\n validation rules](/identity/protocols/oauth2/web-server#uri-validation).\n\n6. After creating your credentials, download the **client_secret.json** file. Securely store the file in a location that only your application can access.\n\nFrom here, follow the steps to [obtain OAuth 2.0 access tokens](/identity/protocols/oauth2/web-server#obtainingaccesstokens)\n\n### Local development\n\nSet up Application Default Credentials (ADC) in your local environment.\n\nInstall the Google Cloud CLI, then initialize it by running the following\ncommand: \n\n gcloud init\n\nCreate local authentication credentials for your Google Account and set\nthe project ID to a project where the Ad Manager API is enabled: \n\n gcloud auth application-default login --scopes=\"https://www.googleapis.com/auth/admanager\"\n gcloud auth application-default set-quota-project \u003cvar label=\"project id\" translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e\n\nAlternatively, authenticate as a Service Account setting the environment\nvariable `GOOGLE_APPLICATION_CREDENTIALS` to the path of your key file.\n\n#### Linux or macOS\n\n export GOOGLE_APPLICATION_CREDENTIALS=\u003cvar label=\"key file\" translate=\"no\"\u003eKEY_FILE_PATH\u003c/var\u003e\n\n#### Windows\n\n set GOOGLE_APPLICATION_CREDENTIALS=\u003cvar label=\"key file\" translate=\"no\"\u003eKEY_FILE_PATH\u003c/var\u003e\n\nConfigure your Ad Manager network\n---------------------------------\n\n**Tip:** If you are a third-party developer, ask your client to complete this step for you. Send them to [Add a service account user for API access](//support.google.com/admanager/answer/6078734) and provide the email address of your service account. \n\n### Service Account\n\n1. Go to your [Ad Manager network](//admanager.google.com).\n2. Click the **Admin** tab.\n3. Ensure that **API access** is enabled.\n4. Click the **Add a service account user** button.\n5. Fill in the form using the service account email. The service account user must be added to appropriate roles and teams for your API integration.\n6. Click the **Save** button. A message should appear, confirming the addition of your service account.\n7. View existing service account users by going to the Users tab and then clicking the **Service Account** filter.\n\n### Web application\n\n1. Go to your [Ad Manager network](//admanager.google.com).\n2. Click the **Admin** tab.\n3. Ensure that **API access** is enabled.\n\n### Local Development\n\n1. Go to your [Ad Manager network](//admanager.google.com).\n2. Click the **Admin** tab.\n3. Ensure that **API access** is enabled.\n\nWithout a client library\n------------------------\n\nIf you are not using a client library, we still strongly recommend using\nan OAuth2 library for authentication.\n\nFor detailed instructions on obtaining access tokens, see\n[Using OAuth2 with Google APIs](/identity/protocols/oauth2).\n\n### Access tokens\n\nInclude your access token in a request to the API by including either an\n`access_token` query parameter or an `Authorization` HTTP header `Bearer` value.\nWhen possible, the HTTP header is preferable, because query strings tend to be\nvisible in server logs.\n\nFor example: \n\n GET /v1/networks/1234\n Host: admanager.googleapis.com\n Authorization: Bearer ya29.a0Ad52N3_shYLX\n\n GET https://admanager.googleapis.com/v1/networks/1234?access_token=1/fFAGRNJru1FTz70BzhT3Zg\n\n### Scope\n\nEach access token is associated with one or more scopes. A scope controls the\nset of resources and operations that an access token permits. The Ad Manager\nAPI has only one scope. Authorization should be performed at the user\nlevel within the product.\n\n| Scope | Permissions |\n|---------------------------------------------|------------------------------------------------------|\n| `https://www.googleapis.com/auth/admanager` | View and manage your campaigns on Google Ad Manager. |"]]