gpt4 book ai didi

admob - 使用 AdMob AppOpenAds 时如何解决此错误?错误 : Code: 1

转载 作者:行者123 更新时间:2023-12-03 18:00:34 26 4
gpt4 key购买 nike

实现 Google AdMob AppOpenAds 时出现此错误。我使用 Android Emulator ID 作为测试设备,并使用 Google 测试广告单元进行 AppOpenAd。我试过在物理设备和模拟器上测试。
我正在使用我自己的 AdMob app-id 和定位 SDK 30。
这是调试控制台中的错误消息。

D/AppOpenManager: {
"Code": 1,
"Message": "Error building request URL.",
"Domain": "com.google.android.gms.ads",
"Cause": "null",
"Response Info": {
"Response ID": "null",
"Mediation Adapter Class Name": "",
"Adapter Responses": []
}
}
我遵循了 https://developers.google.com/ad-manager/mobile-ads-sdk/android/app-open-ads 上提供的文档
这是我的完整代码:
    /** Request an ad */
public void fetchAd() {
// Have unused ad, no need to fetch another.
if (isAdAvailable()) {
return;
}

loadCallback =
new AppOpenAd.AppOpenAdLoadCallback() {
/**
* Called when an app open ad has loaded.
*
* @param ad the loaded app open ad.
*/
@Override
public void onAppOpenAdLoaded(AppOpenAd ad) {
AppOpenManager.this.appOpenAd = ad;
AppOpenManager.this.loadTime = (new Date()).getTime();
}

/**
* Called when an app open ad has failed to load.
*
* @param loadAdError the error.
*/
@Override
public void onAppOpenAdFailedToLoad(LoadAdError loadAdError) {
Log.d(LOG_TAG, loadAdError.toString());
Log.d(LOG_TAG, "AppOpen ad failed to load");
}

};
AdRequest request = getAdRequest();
AppOpenAd.load(
myApplication,
String.valueOf(R.string.app_open_ad_unit_id),
request,
AppOpenAd.APP_OPEN_AD_ORIENTATION_PORTRAIT,
loadCallback);
}

/** Creates and returns ad request. */
private AdRequest getAdRequest() {

/** Add test devices here*/

List<String> testDeviceIds = Arrays.asList(AdRequest.DEVICE_ID_EMULATOR);
RequestConfiguration configuration =
new RequestConfiguration.Builder().setTestDeviceIds(testDeviceIds).build();
MobileAds.setRequestConfiguration(configuration);

return new AdRequest.Builder().build();
}

/** Utility method to check if ad was loaded more than n hours ago. */
private boolean wasLoadTimeLessThanNHoursAgo(long numHours) {
long dateDifference = (new Date()).getTime() - this.loadTime;
long numMilliSecondsPerHour = 3600000;
return (dateDifference < (numMilliSecondsPerHour * numHours));
}


/** Utility method that checks if ad exists and can be shown. */
public boolean isAdAvailable() {
return appOpenAd != null && wasLoadTimeLessThanNHoursAgo(4);

}
/** Shows the ad if one isn't already showing. */
public void showAdIfAvailable() {
// Only show ad if there is not already an app open ad currently showing
// and an ad is available.
if (!isShowingAd && isAdAvailable()) {
Log.d(LOG_TAG, "Will show ad.");

FullScreenContentCallback fullScreenContentCallback =
new FullScreenContentCallback() {
@Override
public void onAdDismissedFullScreenContent() {
// Set the reference to null so isAdAvailable() returns false.
AppOpenManager.this.appOpenAd = null;
isShowingAd = false;
fetchAd();
}

@Override
public void onAdFailedToShowFullScreenContent(AdError adError) {
Log.d(LOG_TAG, "Ad Failed To Show FullScreen Content");
}

@Override
public void onAdShowedFullScreenContent() {
isShowingAd = true;
}
};

appOpenAd.show(currentActivity, fullScreenContentCallback);

} else {
Log.d(LOG_TAG, "Can not show ad.");
fetchAd();
}
}

最佳答案

我有同样的错误
但我犯了一个错误
我在 ads:adUnitId 中添加了 app id

<com.google.android.gms.ads.AdView xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="@+id/adView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
ads:adSize="SMART_BANNER"
ads:adUnitId="XXX"
ads:layout_constraintBottom_toBottomOf="parent" />
而不是 unitid
问题解决了

关于admob - 使用 AdMob AppOpenAds 时如何解决此错误?错误 : Code: 1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65279171/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com