با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
کتابخانههای مشتری ما بهطور خودکار از جزئیات زیر مراقبت میکنند، بنابراین فقط در صورتی به خواندن ادامه دهید که به آنچه در پشت صحنه اتفاق میافتد علاقهمند هستید، یا اگر از یکی از کتابخانههای مشتری ما استفاده نمیکنید.
یک نشانه دسترسی واحد می تواند درجات مختلفی از دسترسی را به چندین API بدهد. پارامتر متغیری به نام scope مجموعه منابع و عملیاتی را که یک نشانه دسترسی اجازه می دهد را کنترل می کند. در طول درخواست نشانه دسترسی، برنامه شما یک یا چند مقدار را در پارامتر scope ارسال می کند.
دامنه Google Ads API عبارت است از:
https://www.googleapis.com/auth/adwords
دسترسی آفلاین
معمولاً یک برنامه مشتری Google Ads API درخواست دسترسی آفلاین می کند. به عنوان مثال، برنامه شما ممکن است بخواهد کارهای دسته ای را اجرا کند، زمانی که کاربر شما به طور فیزیکی آنلاین در حال مرور وب سایت شما نیست.
برای درخواست دسترسی آفلاین برای یک نوع برنامه وب، مطمئن شوید که پارامتر access_type روی offline تنظیم کرده اید. می توانید اطلاعات بیشتری را در راهنمای OAuth2 Google بیابید.
برای نوع برنامه دسکتاپ، دسترسی آفلاین به طور پیشفرض فعال است — لازم نیست صریحاً آن را درخواست کنید.
درخواست سرصفحه ها
هدرهای gRPC
هنگام استفاده از gRPC API، توکن دسترسی را در هر درخواست اضافه کنید. میتوانید Credential برای استفاده در تمام درخواستهای آن Channel به کانال متصل کنید. همچنین می توانید برای هر تماس یک اعتبار شخصی سازی شده ارسال کنید. راهنمای مجوز gRPC حاوی جزئیات بیشتری در مورد مدیریت مجوز است.
سرصفحه های REST
هنگام استفاده از REST API، رمز دسترسی را از طریق Authorization سرصفحه HTTP عبور دهید. نمونه درخواست HTTP در زیر نشان داده شده است:
در بیشتر موارد، برای استفاده در آینده باید توکن رفرش را به صورت ایمن ذخیره کنید. برای کسب اطلاعات بیشتر در مورد نحوه درخواست دسترسی و بهروزرسانی نشانهها، راهنمای مربوطه را برای نوع برنامه خود بخوانید:
یک نشانه دسترسی دارای یک زمان انقضا است (بر اساس مقدار expires_in ) که پس از آن رمز دیگر معتبر نیست. شما می توانید از نشانه refresh برای بازخوانی یک نشانه دسترسی منقضی شده استفاده کنید. به طور پیش فرض، کتابخانه های مشتری ما به طور خودکار نشانه های دسترسی منقضی شده را بازخوانی می کنند.
تاریخ آخرین بهروزرسانی 2025-09-03 بهوقت ساعت هماهنگ جهانی.
[[["درک آسان","easyToUnderstand","thumb-up"],["مشکلم را برطرف کرد","solvedMyProblem","thumb-up"],["غیره","otherUp","thumb-up"]],[["اطلاعاتی که نیاز دارم وجود ندارد","missingTheInformationINeed","thumb-down"],["بیشازحد پیچیده/ مراحل بسیار زیاد","tooComplicatedTooManySteps","thumb-down"],["قدیمی","outOfDate","thumb-down"],["مشکل ترجمه","translationIssue","thumb-down"],["مشکل کد / نمونهها","samplesCodeIssue","thumb-down"],["غیره","otherDown","thumb-down"]],["تاریخ آخرین بهروزرسانی 2025-09-03 بهوقت ساعت هماهنگ جهانی."],[[["\u003cp\u003eThis guide is for advanced users familiar with OAuth 2.0 and its use with Google APIs, offering behind-the-scenes details on authentication with the Google Ads API.\u003c/p\u003e\n"],["\u003cp\u003eAccess tokens control API access, determined by the 'scope' parameter, with the Google Ads API scope being \u003ccode\u003ehttps://www.googleapis.com/auth/adwords\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eOffline access is available for client apps; web apps require setting \u003ccode\u003eaccess_type\u003c/code\u003e to \u003ccode\u003eoffline\u003c/code\u003e, while desktop apps have it enabled by default.\u003c/p\u003e\n"],["\u003cp\u003eAccess tokens are passed via the \u003ccode\u003eAuthorization\u003c/code\u003e HTTP header for REST or bound to a \u003ccode\u003eChannel\u003c/code\u003e for gRPC, and can be refreshed using a securely stored refresh token.\u003c/p\u003e\n"],["\u003cp\u003eClient libraries automatically handle token refresh, but developers can consult guides for desktop and web app token management.\u003c/p\u003e\n"]]],[],null,["# OAuth2 Internals for Google Ads API\n\nOur client libraries automatically take care of the details covered below, so\ncontinue reading only if you're interested in what's happening behind the\nscenes, or if you're not using one of our client libraries.\n\nThis section is intended for advanced users who are already familiar\nwith the [OAuth 2.0 specification](//tools.ietf.org/html/rfc6749) and\nknow how to [use OAuth2 with Google APIs](/identity/protocols/oauth2).\n| **Note:** The Google Ads API does not currently support simultaneous signin with data access request (hybrid) or domain-wide delegation of authority (2LO).\n\n#### Want to learn more about authentication in the API?\n\n\nvideo_library\n[Video library: Authentication and Authorization](/google-ads/api/videos/catalog#authentication-authorization)\n\nScope\n-----\n\nA single access token can grant varying degrees of access to multiple APIs. A\nvariable parameter called `scope` controls the set of resources and operations\nthat an access token permits. During the access token request, your app\nsends one or more values in the `scope` parameter.\n\nThe scope for the Google Ads API is: \n\n https://www.googleapis.com/auth/adwords\n\nOffline access\n--------------\n\nIt's common for a Google Ads API client app to request offline access. For example,\nyour app may want to run batch jobs when your user is not physically online\nbrowsing your website.\n\nTo request offline access for a web app type, make sure you set the\n`access_type` parameter to `offline`. You can find additional information in\n[Google's OAuth2 guide](/identity/protocols/oauth2/web-server#offline).\n\nFor the desktop app type, offline access is enabled by default---you\ndon't have to explicitly request it.\n\nRequest headers\n---------------\n\n### gRPC headers\n\nWhen using the gRPC API, include the access token in each request. You can bind\na `Credential` to a `Channel` for use on all requests on that channel. You can\nalso send a customized credential for each call. The [gRPC\nAuthorization guide](//grpc.io/docs/guides/auth.html) contains more\ndetails on handling authorization.\n\n### REST headers\n\nWhen using the REST API, pass the access token through the HTTP header\n`Authorization`. An example HTTP request is shown below: \n\n```http\nGET /v21/customers/\u003cvar translate=\"no\"\u003e123456789\u003c/var\u003e HTTP/2\nHost: googleads.googleapis.com\nUser-Agent: INSERT_USER_AGENT\nAccept: */*\nAuthorization: Bearer \u003cvar translate=\"no\"\u003eINSERT_ACCESS_TOKEN\u003c/var\u003e\ndeveloper-token: INSERT_DEVELOPER_TOKEN\n```\n\nAccess and refresh token\n------------------------\n\nIn most cases, you need to store the refresh token securely for future use.\nTo learn more about how to request access and refresh tokens, read the\ncorresponding guide for your application type:\n\n- [Desktop app](/identity/protocols/oauth2/native-app)\n- [Server-side web app](/identity/protocols/oauth2/web-server)\n\nRefresh token expiration\n------------------------\n\nFor more details about the refresh token expiration, refer to the [Google\nIdentity Platform OAuth documentation](/identity/protocols/oauth2#expiration).\n\nAccess token expiration\n-----------------------\n\nAn access token has an expiration time (based on the\n[`expires_in`](//tools.ietf.org/html/rfc6749#appendix-A.14) value) after\nwhich the token is no longer valid. You can use the refresh token to refresh\nan expired access token. By default, our client libraries automatically\nrefresh expired access tokens."]]