Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Tất cả các lệnh gọi API Google AdMob đều phải được uỷ quyền thông qua OAuth2 để ứng dụng của bạn có thể tương tác với các dịch vụ web thay cho người dùng. OAuth2 cho phép ứng dụng AdMob API của bạn truy cập vào tài khoản AdMob của người dùng mà không cần xử lý hoặc lưu trữ tên người dùng hoặc mật khẩu của người dùng. Để biết thông tin tổng quan về việc uỷ quyền, hãy xem phần Uỷ quyền.
Thực hiện các bước sau để tạo thông tin xác thực OAuth2 và đưa ra yêu cầu đầu tiên.
Hãy xem bảng dưới đây để biết loại xác thực nào phù hợp nhất với ứng dụng của bạn:
Chọn loại xác thực OAuth2
Nếu ...
Ứng dụng dành cho máy tính
Bạn đang quản lý tất cả các tài khoản AdMob API bằng một tài khoản người quản lý cấp cao nhất duy nhất.
Bạn là người dùng lần đầu hoặc muốn bắt đầu nhanh chóng với chế độ thiết lập đơn giản nhất.
Ứng dụng của bạn chỉ xác thực người dùng Google AdMob trên một máy.
Ứng dụng web
Bạn muốn xác thực với tư cách là người dùng có thể cấp quyền cho ứng dụng của bạn truy cập vào dữ liệu tài khoản AdMob API của họ.
Bạn muốn dễ dàng tạo nhiều thông tin uỷ quyền, chẳng hạn như để quản lý tài khoản của bên thứ ba.
Ứng dụng của bạn yêu cầu URL gọi lại. URL gọi lại không được hỗ trợ trong quy trình ứng dụng dành cho máy tính.
Tạo một dự án
Để bắt đầu sử dụng API AdMob, trước tiên bạn cần tạo hoặc chọn một dự án trong Google API Console và bật API bằng công cụ thiết lập. Công cụ này sẽ hướng dẫn bạn trong quy trình và tự động kích hoạt API AdMob.
Bật API cho một dự án hiện có
Các bước sau đây áp dụng cho những người dùng có dự án hiện tại và muốn kích hoạt AdMob API cho dự án đó theo cách thủ công.
If prompted, select a project, or create a new one. Thư viện API API Library liệt kê tất cả những API có sẵn, được nhóm theo nhóm sản phẩm và mức độ phổ biến.
Nếu API bạn muốn bật không xuất hiện trong danh sách, hãy sử dụng chức năng tìm kiếm để tìm API đó hoặc nhấp vào Xem tất cả trong nhóm sản phẩm mà API đó thuộc về.
Chọn API bạn muốn bật, sau đó nhấp vào nút Bật.
If prompted, enable billing.
If prompted, read and accept the API's Terms of Service.
Tạo thông tin đăng nhập OAuth2
Các hướng dẫn sau đây sẽ hướng dẫn bạn quy trình tạo mã ứng dụng khách OAuth 2.0 để sử dụng với quy trình ứng dụng đã cài đặt.
Nhấp vào TẠO THÔNG TIN XÁC THỰC > Mã ứng dụng OAuth.
Nếu trước đây chưa định cấu hình màn hình xin phép bằng OAuth cho dự án này, thì bạn sẽ được hướng dẫn thực hiện ngay. Nhấp vào ĐỊNH CẤU HÌNH MÀN HÌNH YÊU CẦU SỰ ĐỒNG Ý. Có nhiều cách để định cấu hình màn hình đồng ý nhằm sử dụng mã ứng dụng OAuth 2.0.
Đặt loại người dùng thành Bên ngoài và trạng thái xuất bản thành Đã xuất bản.
Hoặc đặt loại người dùng thành Bên ngoài và trạng thái xuất bản thành Kiểm thử, sau đó thêm Người dùng kiểm thử bằng cách chọn thêm người dùng để cấp cho họ quyền truy cập sử dụng mã ứng dụng OAuth 2.0 của bạn.
Chọn Ứng dụng dành cho máy tính hoặc Ứng dụng web làm loại ứng dụng, đặt tên cho ứng dụng đó, rồi nhấp vào Tạo.
Sau khi hoàn tất, bạn sẽ thấy mã ứng dụng khách và khoá bí mật của ứng dụng khách OAuth 2.0. Bạn có thể tải mã ứng dụng khách và khoá bí mật này xuống ở định dạng JSON và lưu để sử dụng sau.
Tạo yêu cầu
API AdMob được xây dựng trên HTTP và JSON, nhờ đó, mọi ứng dụng HTTP chuẩn đều có thể gửi yêu cầu tới API AdMob và phân tích cú pháp các phản hồi. Tuy nhiên, thư viện ứng dụng Google API cung cấp tính năng tích hợp ngôn ngữ tốt hơn, có mức độ bảo mật cao hơn và hỗ trợ thực hiện các yêu cầu được uỷ quyền. Các thư viện ứng dụng được cung cấp bằng một số ngôn ngữ lập trình. Bằng cách sử dụng các thư viện đó, bạn có thể tránh được việc phải thiết lập yêu cầu HTTP và phân tích cú pháp phản hồi theo cách thủ công.
Sau khi tạo thông tin xác thực OAuth 2.0, bạn đã sẵn sàng bắt đầu sử dụng API AdMob. Để yêu cầu quyền truy cập bằng OAuth 2.0, ứng dụng của bạn cũng cần thông tin về phạm vi:
Xem tất cả dữ liệu AdMob. Dữ liệu này có thể bao gồm thông tin tài khoản, các chế độ cài đặt về khoảng không quảng cáo và chức năng dàn xếp, báo cáo và các dữ liệu khác.
Tuy nhiên, nữ liệu này không bao gồm dữ liệu nhạy cảm (chẳng hạn như thông tin về thanh toán hoặc thông tin chiến dịch).
[[["Dễ hiểu","easyToUnderstand","thumb-up"],["Giúp tôi giải quyết được vấn đề","solvedMyProblem","thumb-up"],["Khác","otherUp","thumb-up"]],[["Thiếu thông tin tôi cần","missingTheInformationINeed","thumb-down"],["Quá phức tạp/quá nhiều bước","tooComplicatedTooManySteps","thumb-down"],["Đã lỗi thời","outOfDate","thumb-down"],["Vấn đề về bản dịch","translationIssue","thumb-down"],["Vấn đề về mẫu/mã","samplesCodeIssue","thumb-down"],["Khác","otherDown","thumb-down"]],["Cập nhật lần gần đây nhất: 2025-08-21 UTC."],[[["\u003cp\u003eAll Google AdMob API calls require OAuth2 authorization for your app to access user data securely without storing sensitive login credentials.\u003c/p\u003e\n"],["\u003cp\u003eChoose between desktop or web app authentication flow based on your app's needs and authorization process.\u003c/p\u003e\n"],["\u003cp\u003eCreate or select a Google API project and enable the AdMob API before generating OAuth2 credentials.\u003c/p\u003e\n"],["\u003cp\u003eMake authorized requests to the AdMob API using HTTP clients or client libraries in various programming languages.\u003c/p\u003e\n"],["\u003cp\u003eRevoke access tokens through your Google account permissions or the Google Identity API when necessary.\u003c/p\u003e\n"]]],["To use the Google AdMob API, authorize calls via OAuth2. First, create or select a project in the Google API Console and enable the AdMob API. Next, create OAuth2 credentials, choosing between \"Desktop app\" or \"Web app\" authentication types based on your needs. Configure the OAuth consent screen, download the generated client ID and secret, and then use these credentials to authorize requests with specified scopes, such as `admob.monetization` or `admob.readonly`. To start making requests, you can utilize the Google API client libraries. If you want to revoke access, you can do so from your Google account or using Google Identity API.\n"],null,["All Google AdMob API calls must be authorized through\n[OAuth2](/identity/protocols/oauth2) so your app can interact with web services\non the user's behalf. OAuth2 enables your AdMob API client app to access a\nuser's AdMob account without having to handle or store the user's username or\npassword. For an overview of authorization, see\n[Authorization](/admob/api/v1/how-tos/authorizing).\n\nPerform the following steps to generate the OAuth2 credentials and make your\nfirst request.\n\nPrerequisites\n\n- A [Google Account](//google.com/accounts/NewAccount).\n\n- A [Google AdMob account](//admob.google.com/home/get-started).\n\n- Familiarity with [REST basics](/admob/api/v1/prereqs#rest) and [authorizing requests with\n OAuth 2.0](/admob/api/v1/how-tos/authorizing).\n\nDetermine your authentication type\n\nCheck the table below to see which **authentication type** is most appropriate\nfor your app:\n\n| Choose your OAuth2 authentication type | If ... |\n|----------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| **Desktop app** | - You're managing all of your AdMob API accounts using a single top level manager account. - You're a first-time user, or want to get started quickly with the simplest setup. - Your app only authenticates Google AdMob users from one machine. |\n| **Web app** | - You want to authenticate as a user who can grant permission to your app to access their AdMob API account data. - You want to easily generate multiple authorization credentials, to manage third-party accounts for example. - Your app requires callback URLs. Callback URLs are not supported in the desktop app flow. |\n\n| **Key Point:** You can still choose the desktop app flow even if you're developing an app to run on a server. The difference is whether the OAuth authorization is completed locally or remotely. A desktop flow requires authorization to be completed on the local machine, whereas the web-flow lets authorization be completed on Google's authorization server.\n\nCreate a project\n\nTo get started using the AdMob API, you need to first create or select a\nproject in the Google API Console and enable the API using [the setup\ntool](https://console.cloud.google.com/start/api?id=admob.googleapis.com&credential=client_key),\nwhich guides you through the process and activates the AdMob API\nautomatically. \n\nEnabling the API for an existing project\n\nThe following steps apply to users who have an existing project and prefer to\nactivate the AdMob API for it manually.\n\nTo enable an API for your project:\n\n1. [Open the API Library](https://console.developers.google.com/apis/library) in the Google API Console.\n2. If prompted, select a project, or create a new one. The API Library lists all available APIs, grouped by product family and popularity.\n3. If the API you want to enable isn't visible in the list, use search to find it, or click **View All** in the product family it belongs to.\n4. Select the API you want to enable, then click the **Enable** button.\n5. If prompted, enable billing.\n6. If prompted, read and accept the API's Terms of Service.\n\nCreate OAuth2 credentials\n\nThe following instructions guide you through the process of creating an OAuth\n2.0 client ID to use with the [installed app\nflow](/identity/protocols/OAuth2InstalledApp).\n\n1. Go to the [Clients page](https://console.developers.google.com/auth/clients).\n2. Click **CREATE CREDENTIALS \\\u003e OAuth client ID**.\n\n If you hadn't configured an OAuth consent screen for this project\n previously, you'll be directed to do so now. Click **CONFIGURE CONSENT\n SCREEN**. There are multiple ways to configure your consent screen to\n use your OAuth 2.0 client ID.\n 1. Set your user type to **External** and publishing status to **Published**.\n 2. Or, set your user type to **External** and publishing status to\n **Testing** , then add **Test users** by selecting **add users** to\n give them access to use your OAuth 2.0 client ID.\n\n See additional information on [setting up your OAuth consent\n screen](//support.google.com/cloud/answer/10311615).\n3. Select **Desktop app** or **Web Application** as the application type, give\n it a name, then click **Create**.\n\nWhen done, you are presented with an OAuth 2.0 client ID and client secret,\nwhich you can download in JSON format and save for later use.\n\nMake a request\n\nThe AdMob API is built on HTTP and JSON, so any standard HTTP client can send\nrequests to it and parse the responses. However, the [Google API client\nlibraries](/admob/api/v1/libraries) provide better language integration,\nimproved security, and support for making authorized requests. The client\nlibraries are available in a number of programming languages; by using them you\ncan avoid the need to manually set up HTTP requests and parse the responses.\n| **Note:** The first time you activate the OAuth flow, you are asked to provide your AdMob publisher ID and accept an authorization prompt in your browser. Before accepting, make sure you're signed in with a Google Account that has access to your AdMob account. Your app is then authorized to access data on behalf of whichever account is currently logged in.\n\nWith [OAuth 2.0 credentials created](#credentials), you're ready to start using\nthe AdMob API. To request access using OAuth 2.0, your app also needs scope\ninformation:\n\n\n| Scope | Meaning |\n|--------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `https://www.googleapis.com/auth/admob.readonly` | See all AdMob data. This may include account information, inventory and mediation settings, reports, and other data. This doesn't include sensitive data, such as payments or campaign details. |\n| `https://www.googleapis.com/auth/admob.report` | See ad performance and earnings reports. See publisher ID, timezone, and default currency code. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\nMake your first request to generate a report using examples in\n[Java](/admob/api/v1/reporting#java-client-library),\n[PHP](/admob/api/v1/reporting#php-client-library),\n[Python](/admob/api/v1/reporting#python-client-library) or\n[curl](/admob/api/v1/reporting#curl-command-line).\n\nRevoke shared tokens\n\nYou can revoke shared tokens in two ways:\n\n1. Navigate to your [Google account\n permissions page](//myaccount.google.com/permissions) and revoke access from\n the relevant project.\n\n2. Alternatively, you can revoke web application tokens using the [Google\n Identity API](/identity/protocols/oauth2/web-server#tokenrevoke)."]]