廣告載入錯誤
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());
}
}
您可以利用這項資訊,更準確地判斷廣告載入失敗的原因。特別是,如果您在 iOS 的 com.google.admob
和 Android 的 com.google.android.gms.ads
網域中看到錯誤訊息,可以參閱這篇說明中心文章,進一步瞭解錯誤訊息的詳細說明,以及可能需要採取的解決問題行動。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-02-23 (世界標準時間)。
[null,null,["上次更新時間: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"]]