正如 Mopub 的文档说here一样,整合了原生广告,然后是原生视频广告。
在整合代码后,广告请求响应正在调用回调方法onNativeFail()
有一些回应
以下代码与工作流程和logcat消息相关
公共类MainActivity扩展了Activity {
private MoPubView moPubView;
//private MoPubInterstitial mInterstitial;
private MoPubNative moPubNative;
private MoPubNativeNetworkListener moPubNativeNetworkListener;
private NativeAd.MoPubNativeEventListener moPubNativeEventListener;
AdapterHelper adapterHelper;
private NativeFullScreenVideoView nativeFullScreenVideoView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
moPubNativeNetworkListener = new MoPubNativeNetworkListener() {
@Override
public void onNativeLoad(NativeAd nativeAd) {
Log.d("MoPub", "Native ad has loaded.");
}
@Override
public void onNativeFail(NativeErrorCode errorCode) {
Log.d("MoPub", "Native ad failed to load with error: " + errorCode.toString());
}
};
moPubNativeEventListener = new NativeAd.MoPubNativeEventListener() {
@Override
public void onImpression(View view) {
Log.d("MoPub", "Native ad recorded an impression.");
// Impress is recorded - do what is needed AFTER the ad is visibly shown here.
}
@Override
public void onClick(View view) {
Log.d("MoPub", "Native ad recorded a click.");
// Click tracking.
}
};
moPubNative = new MoPubNative(this, "02a2d288d2674ad09f3241d46a44356e ", moPubNativeNetworkListener);
ViewBinder viewBinder = new ViewBinder.Builder(R.layout.native_ad_list_item)
.mainImageId(R.id.native_main_image)
.iconImageId(R.id.native_icon_image)
.titleId(R.id.native_title)
.textId(R.id.native_text)
.privacyInformationIconImageId(R.id.native_privacy_information_icon_image)
.build();
MediaViewBinder mediaViewBinder = new MediaViewBinder.Builder(R.layout.native_video_ad_layout)
.mediaLayoutId(R.id.native_ad_video_view)
.iconImageId(R.id.native_ad_icon_image)
.titleId(R.id.native_ad_title)
.textId(R.id.native_ad_text)
.build();
MoPubVideoNativeAdRenderer moPubVideoNativeAdRenderer = new MoPubVideoNativeAdRenderer(mediaViewBinder);
moPubNative.registerAdRenderer(moPubVideoNativeAdRenderer);
MoPubStaticNativeAdRenderer moPubStaticNativeAdRenderer = new MoPubStaticNativeAdRenderer(viewBinder);
moPubNative.registerAdRenderer(moPubStaticNativeAdRenderer);
EnumSet<RequestParameters.NativeAdAsset> desiredAssets = EnumSet.of(
RequestParameters.NativeAdAsset.TITLE,
RequestParameters.NativeAdAsset.TEXT,
RequestParameters.NativeAdAsset.CALL_TO_ACTION_TEXT,
RequestParameters.NativeAdAsset.MAIN_IMAGE,
RequestParameters.NativeAdAsset.ICON_IMAGE,
RequestParameters.NativeAdAsset.STAR_RATING
);
RequestParameters mRequestParameters = new RequestParameters.Builder()
.desiredAssets(desiredAssets)
.build();
moPubNative.makeRequest();
}
}
运行此代码后,广告未加载,我的代码响应低于
06-06 17:01:41.797 24421-24421/? I/Ads: Webview loading for native ads.
06-06 17:01:41.911 24421-24421/? I/Ads: Javascript has loaded for native ads.
06-06 17:02:18.623 24421-24421/? I/Ads: Webview loading for native ads.
06-06 17:02:18.954 24421-24421/? I/Ads: Javascript has loaded for native ads.
06-06 17:02:51.796 13278-13278/com.fabgrad.students.android D/MoPub: Native ad request failed.
com.mopub.network.MoPubNetworkError: No ads found for ad unit.
at com.mopub.network.AdRequest.parseNetworkResponse(AdRequest.java:180)
at com.mopub.volley.NetworkDispatcher.processRequest(NetworkDispatcher.java:132)
at com.mopub.volley.NetworkDispatcher.run(NetworkDispatcher.java:87)
06-06 17:02:51.800 13278-13278/com.fabgrad.students.android D/MoPub: Native ad failed to load with error: Server returned empty response.
答案 0 :(得分:0)
根据他们的博客,在以下情况下找不到广告:
这些错误表明您的广告单元没有空位。 没有广告网络会在100%的时间内充满广告,因此看到此日志是正常的。新应用程序和体积很小的应用程序的填充率往往较低。如果您对特定广告网络的填充有任何疑问,请与您的广告网络代表联系。
如果始终看不到填充,请在MoPub UI的“网络”标签中查看您的广告网络展示位置详细信息,并在“网络” UI中查看您的设置。
如果您忘记包含网络SDK或适配器文件,则将无法展示来自认证广告网络的广告。 “无法找到或实例化自定义事件”和“找不到本机网络”或“自定义事件”适配器日志消息是网络SDK或适配器文件丢失,重命名或位置错误的指示。
查看我们的集成第三方广告网络文档以解决此问题。
Link供参考。