广告加载错误

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 中)下的错误,可以在这篇帮助中心文章中查找相应消息,以获取更详细的说明以及可以采取哪些措施来解决该问题。