广告加载错误
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
AdResult
对象提供了一种检测广告加载失败尝试的机制。如果发生故障,AdResult
方法 is_successful()
将返回 false。在这些情况下,调用 AdResult
方法 ad_error()
将返回一个包含与错误相关信息的 AdError
对象。
以下代码段说明了广告加载失败时可用的信息:
firebase::Future<firebase::gma::AdResult> load_ad_future =
ad_view->LoadAd(request);
// In a game loop, monitor the load ad status
if (load_ad_future.status() == firebase::kFutureStatusComplete) {
const firebase::gma::AdResult* ad_result = load_ad_future.result();
if (!ad_result.is_successful()) {
// There was an error loading the ad.
const AdError& ad_error = ad_result.ad_error();
firebase::gma::AdErrorCode code = ad_error.code();
std::string domain = ad_error.domain();
std::string message = ad_error.message();
const firebase::gma::ResponseInfo response_info = ad_error.response_info();
printf("Received error with domain: %s, code: %d, message: %s and response info: %s\n”,
domain.c_str(), message.c_str(), response_info.ToString().c_str());
}
}
此信息可用于更准确地确定导致广告加载失败的原因。需要特别指出的是,对于网域 com.google.admob
(在 iOS 上)和 com.google.android.gms.ads
(在 Android 上)下的错误,可在这篇帮助中心文章中查询相应消息,以获取更多详细说明并了解可以采取哪些措施来解决相应问题。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-31。
[null,null,["最后更新时间 (UTC):2025-08-31。"],[[["\u003cp\u003eThe Google Mobile Ads C++ SDK is deprecated and will be end-of-maintenance on June 17, 2025, with iOS and Android SDKs recommended as alternatives.\u003c/p\u003e\n"],["\u003cp\u003eDevelopers should use \u003ccode\u003eAdResult\u003c/code\u003e objects, specifically the \u003ccode\u003eis_successful()\u003c/code\u003e and \u003ccode\u003ead_error()\u003c/code\u003e methods, to detect and diagnose ad loading failures.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eAdError\u003c/code\u003e objects provide detailed error information, including domain, code, and message, for troubleshooting failed ad loads.\u003c/p\u003e\n"],["\u003cp\u003eError messages can be cross-referenced with the Google AdMob help center to identify the root cause and potential solutions.\u003c/p\u003e\n"]]],["The Google Mobile Ads C++ SDK is deprecated as of June 17, 2024, and will reach End-of-Maintenance on June 17, 2025. AdMob iOS and Android SDKs are recommended alternatives. `AdResult` objects detect failed ad loads; `is_successful()` indicates success, and `ad_error()` retrieves an `AdError` object for failures. The `AdError` includes error domain, code, message, and response info, which can be used to troubleshoot. Refer to the Google help center for specific error resolutions.\n"],null,["# Ad load errors\n\n| **DEPRECATED:** The Google Mobile Ads C++ SDK is *deprecated* as of June 17, 2024 and should not be adopted in projects that don't already use it. It will enter *End-of-Maintenance (EoM)* on June 17, 2025. Note that versions of the SDK released before the EoM date will continue to function, but no further bug fixes or changes will be released after the EoM date.\n|\n| Instead of the Google Mobile Ads C++ SDK, consider using the\n| [iOS](/admob/ios/quick-start) and\n| [Android](/admob/android/quick-start) SDKs from AdMob.\n| For support, reach out to the\n| [Google Mobile Ads SDK Technical Forum](https://groups.google.com/g/google-admob-ads-sdk).\n\n\u003cbr /\u003e\n\n`AdResult` objects provide a mechanism to detect failed attempts to load an ad.\nIf a failure occurs, the `AdResult` method `is_successful()` will return false.\nIn these situations, invoking the `AdResult` method `ad_error()` will return an\n`AdError` object with information pertaining to the error.\n\nHere is a code snippet that illustrates the information available when an ad\nfails to load: \n\n firebase::Future\u003cfirebase::gma::AdResult\u003e load_ad_future =\n ad_view-\u003eLoadAd(request);\n\n // In a game loop, monitor the load ad status\n if (load_ad_future.status() == firebase::kFutureStatusComplete) {\n const firebase::gma::AdResult* ad_result = load_ad_future.result();\n if (!ad_result.is_successful()) {\n // There was an error loading the ad.\n const AdError& ad_error = ad_result.ad_error();\n firebase::gma::AdErrorCode code = ad_error.code();\n std::string domain = ad_error.domain();\n std::string message = ad_error.message();\n const firebase::gma::ResponseInfo response_info = ad_error.response_info();\n printf(\"Received error with domain: %s, code: %d, message: %s and response info: %s\\n\",\n domain.c_str(), message.c_str(), response_info.ToString().c_str());\n }\n }\n\nThis information can be used to more accurately determine what caused the ad\nload to fail. In particular, for errors under the domain `com.google.admob` on\niOS and `com.google.android.gms.ads` on Android, the message can be looked up in\nthis [help center article](//support.google.com/admob/answer/9905175) for a more\ndetailed explanation and possible actions that can be taken to resolve the\nissue."]]