我试图理解为什么收到“未找到广告” 错误消息。
来自Facebook受众群体网络(FAN)的本地广告在Android RecyclerView 中展示,其投放方式与测试广告单元在以下屏幕截图中的展示方式相同。
对于原生广告,我一直遵循Android setup。该应用尚未在Play商店中投放,因为它仍在测试中。
AndroidManifest.xml
...
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="[app-package-here]">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:allowBackup="true"
android:icon="@drawable/logo"
android:label="@string/app_name"
android:networkSecurityConfig="@xml/network_security_config"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<activity android:name="[app-package-here].MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.mopub.common.privacy.ConsentDialogActivity" android:configChanges="keyboardHidden|orientation|screenSize"/>
<activity android:name="com.mopub.common.MoPubBrowser" android:configChanges="keyboardHidden|orientation|screenSize"/>
</application>
</manifest>
network_security_config.xml
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<base-config cleartextTrafficPermitted="true">
<trust-anchors>
<certificates src="system"/>
</trust-anchors>
</base-config>
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">127.0.0.1</domain>
<domain includeSubdomains="true">example.com</domain>
<domain includeSubdomains="true">cdn.example2.com</domain>
</domain-config>
</network-security-config>
build.gradle (模块)
implementation('com.mopub:mopub-sdk-native-static:5.4.1@aar') {
transitive = true
}
implementation 'com.facebook.android:audience-network-sdk:5.1.0'
implementation 'com.mopub.mediation:facebookaudiencenetwork:5.1.0.0'
build.gradle (应用程序)
buildscript {
ext.kotlin_version = '1.3.11'
repositories {
google()
jcenter()
mavenCentral()
maven { url 'https://maven.google.com' }
maven { url "https://s3.amazonaws.com/moat-sdk-builds" }
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.gms:google-services:4.2.0'
classpath "android.arch.navigation:navigation-safe-args-gradle-plugin:1.0.0-alpha09"
}
}
allprojects {
repositories {
google()
jcenter()
maven { url "https://s3.amazonaws.com/moat-sdk-builds" }
}
}
MainActivity
val sdkConfiguration = SdkConfiguration.Builder([ad-unit-id-here])
.build()
MoPub.initializeSdk(this, sdkConfiguration, initSdkListener())
活动/片段
private fun populateAdapterType() {
moPubAdapter = MoPubRecyclerAdapter(activity!!, adapter,
MoPubNativeAdPositioning.MoPubServerPositioning())
val moPubStaticNativeAdRenderer = MoPubStaticNativeAdRenderer(
ViewBinder.Builder(R.layout.native_ad_list_item)
.titleId(R.id.native_title)
.textId(R.id.native_text)
.mainImageId(R.id.native_main_image)
.iconImageId(R.id.native_icon_image)
.callToActionId(R.id.native_cta)
.privacyInformationIconImageId(R.id.native_privacy_information_icon_image)
.build()
)
moPubAdapter.registerAdRenderer(moPubStaticNativeAdRenderer)
contentRecyclerView.adapter = moPubAdapter
moPubAdapter.loadAds([ad-unit-id-here])
}
App
广告单元
网络
细分
测试广告单元ID 11a17b188668469fb0412708c3d16813 成功显示。但是,使用在MoPub控制台中创建的广告单元ID时,不会显示实时Facebook广告。
错误:“ MoPubNetworkError:找不到广告单元的广告”
完全错误
2019-01-11 18:46:12.312 29624-29624 / [app-package-here] D / MoPub:MoPubNative正在从以下位置加载广告:https://ads.mopub.com/m/ad?id=[ad-id-here]&nv=5.4.1&dn=Google%2CPixel%202%2Cwalleye&bundle=[app-package-here]&z=-0800&o=p&w=1080&h=1920&sc=2.625&mcc=310&mnc=260&cn=Google%20Fi&ct=2&av=0.15&udid=mp_tmpl_advertising_id&dnt=mp_tmpl_do_not_track&gdpr_applies=0&force_gdpr_applies=0¤t_consent_status=unknown&MAGIC_NO=0
2019-01-11 18:46:12.689 29624-29624 / [app-package-here] D / MoPub:尝试调用自定义事件:com.mopub.nativeads.FacebookNative
2019-01-11 18:46:13.114 29624-29624 / [app-package-here] D / MoPub:成功命中跟踪端点:https://ads.mopub.com/m/attempt
2019-01-11 18:46:13.205 29624-29624 / [在此处下载应用程序包] W / MoPub:MoPubNative.onNativeAdLoaded com.mopub.nativeads.CustomEventNativeAdapter@708f83c
2019-01-11 18:46:13.206 29624-29624 / [app-package-here] V / MoPub:原生广告加载失败,并显示错误:未为CustomEventNative注册必需的渲染器。.
2019-01-11 18:46:13.394 29624-29624 / [app-package-here] D / MoPub:原生广告请求失败。
com.mopub.network.MoPubNetworkError:找不到广告单元的广告。
com.mopub.network.MultiAdResponse。(MultiAdResponse.java:157)
在com.mopub.network.MultiAdRequest.parseNetworkResponse(MultiAdRequest.java:96)
在com.mopub.volley.NetworkDispatcher.processRequest(NetworkDispatcher.java:132)
在com.mopub.volley.NetworkDispatcher.run(NetworkDispatcher.java:87)
Facebook Ad Request Debugger使用正确的展示位置ID来显示MoPub发出的请求。
Facebook货币管理器
MoPub网络设置> 应用和广告单元设置
Facebook广告请求调试器
我还根据Facebook's testing documentation添加了带有手机的 AAID 的测试设备,因此不在Play商店上线应该不是问题。
答案 0 :(得分:1)
根据MoPub的Integrating 3rd Party Ad Networks,它解释说,除了使用Ad Renderer之外,Facebook还需要唯一的specific Facebook layout。
FacebookAdRenderer facebookAdRenderer = new FacebookAdRenderer( new FacebookAdRenderer.FacebookViewBinder.Builder(R.layout.native_ad_list_item) .titleId(R.id.native_title) .textId(R.id.native_text) // Binding to new layouts from Facebook 4.99.0+ .mediaViewId(R.id.native_main_image) .adIconViewId(R.id.native_icon_image) .adChoicesRelativeLayoutId(R.id.native_ad_choices_relative_layout) .advertiserNameId(R.id.native_title) // Bind either the titleId or advertiserNameId depending on the FB SDK version // End of binding to new layouts .callToActionId(R.id.native_cta) .build());
要了解在XML中为FacebookViewBinder中的MediaView,AdIconView和AdChoices RelativeLayout使用哪些特定的布局元素,请参考此XML布局示例。此外,根据要集成的Facebook SDK版本,您将仅需要显示广告标题或广告客户名称。有关Facebook实施要求的更多信息,请查看本文。
然后,注册您的广告渲染器,如下所示。您的classThatRegistersAdRenderers取决于您所使用的原生广告集成。请记住最后注册您的MoPubStaticNativeAdRenderer实例。
// MoPubRecyclerAdapter MoPubRecyclerAdapter classThatRegistersAdRenderers = new MoPubRecyclerAdapter(...); // MoPubStreamAdPlacer MoPubStreamAdPlacer classThatRegistersAdRenderers = new MoPubStreamAdPlacer(...); // MoPubAdAdapter MoPubAdAdapter classThatRegistersAdRenderers = new MoPubAdAdapter(...); // MoPubNative MoPubNative classThatRegistersAdRenderers = new MoPubNative(...); classThatRegistersAdRenderers.registerAdRenderer( googlePlayServicesAdRenderer); classThatRegistersAdRenderers.registerAdRenderer( flurryNativeAdRenderer); classThatRegistersAdRenderers.registerAdRenderer(facebookAdRenderer); classThatRegistersAdRenderers.registerAdRenderer(staticAdRender);
答案 1 :(得分:0)
当您在 Facebook 上使用 Mopub Mediation 时,您必须使用 FacebookAdRenderer
代替 MoPubStaticNativeAdRenderer