flutter - Flutter firebase_admob 在 testdevice 中不显示广告
问题描述
我无法在我的设备上的测试应用中显示我的广告单元。
我正在使用 firebase_admob 0.9.1+1 插件
这是我使用的代码:
import 'package:firebase_admob/firebase_admob.dart';
Future initAppAds() async {
//Récupère du coup le bon ID selon si je suis sous IOS ou Android
print(getAppId());
await FirebaseAdMob.instance.initialize(appId: 'ca-app-pub-xxxxxxxxMyAppIdxxxxxxxxxxx');
}
Future launchAds() async {
print("launchAds");
print(getInterstitialId());
MobileAdTargetingInfo targetingInfo = MobileAdTargetingInfo(
nonPersonalizedAds: true,
);
InterstitialAd myInterstitial = InterstitialAd(
adUnitId: 'ca-app-pub-xxxxxxxxxxxxx/xxxxMyAdBloc',
targetingInfo: targetingInfo, //Info de l'utilisateur
listener: (MobileAdEvent event) {
print("InterstitialAd event is $event");
},
);
await myInterstitial.load();
await myInterstitial.show(
anchorType: AnchorType.bottom,
anchorOffset: 0.0,
horizontalCenterOffset: 0.0
);
}
这是我得到的日志:
2866-2866/com.fabien.movizz I/Ads: Use RequestConfiguration.Builder().setTestDeviceIds(Arrays.asList("6C11832B439BDE4C399171C8D4CC6515") to get test ads on this device.
6769-3457/? W/Ads: App does not have the required permissions to get location
6769-3539/? I/Ads: SDK version: afma-sdk-a-v20088999.15301000.1
6769-3539/? W/Ads: Received error HTTP response code: 400
2866-2866/com.fabien.movizz I/Ads: Ad failed to load : 0
所以我指定了我的设备的 ID,如下所示:
MobileAdTargetingInfo targetingInfo = MobileAdTargetingInfo(
nonPersonalizedAds: true,
testDevices: <String>["6C11832B439BDE4C399171C8D4CC6515"],
);
但是广告仍然没有出现。这是我得到的日志:
2866-2866/com.fabien.movizz I/Ads: This request is sent from a test device.
6769-3380/? W/Ads: App does not have the required permissions to get location
6769-3457/? I/Ads: SDK version: afma-sdk-a-v20088999.15301000.1
6769-3457/? W/Ads: Received error HTTP response code: 400
2866-2866/com.fabien.movizz I/Ads: Ad failed to load : 0
如果我使用Google 提供的测试广告,广告效果很好,这是我得到的日志:
2866-2866/com.fabien.movizz I/Ads: This request is sent from a test device.
6769-3539/? W/Ads: App does not have the required permissions to get location
6769-5440/? I/Ads: SDK version: afma-sdk-a-v20088999.15301000.1
我的广告单元有什么问题?我在 2 天前创建了它,我是否等待它出现的时间足够长?
谢谢你的帮助 ;)
解决方案
您是Ad failed to load : 0
从 admob 获取的,这意味着您的代码没有错误,您需要稍等片刻。您的广告 ID 是新创建的,因此从谷歌服务器获取广告需要一些时间。
如果您的广告不是新创建的,则错误可能是由于使用错误Admob Application ID
或在某些情况下未将付款信息添加到您的 admob 仪表板。
推荐阅读
- python - 为什么在熊猫数据框上使用 .apply 时会给出不正确的结果?我的循环版本有效
- sql-server - 如何将表变量从 FunctionA 传递到 FunctionB,并将表变量从 FunctionB 返回到 FunctionA?
- mysql - MySQL如何使用join替换外键关系
- c# - 如果我有自定义渲染器和许多外部库,如何混淆 Xamarin Android 代码
- r - R获取字符串中括号之间的字符
- html - IE & Edge 在父 div 后面隐藏框阴影
- python - 根据滞后/变化的变量创建新列
- python - Numpy 数组特定操作
- delphi - 如何显示键入的键的名称?
- kubernetes - 如何将部署的全名传递给 helm values.yaml 中的变量?