广告加载错误
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-02-23。
[null,null,["最后更新时间 (UTC):2025-02-23。"],[[["The 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."],["Developers should use `AdResult` objects, specifically the `is_successful()` and `ad_error()` methods, to detect and diagnose ad loading failures."],["`AdError` objects provide detailed error information, including domain, code, and message, for troubleshooting failed ad loads."],["Error messages can be cross-referenced with the Google AdMob help center to identify the root cause and potential solutions."]]],["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"]]