Flutter firebase_admob在测试设备中不显示广告

时间:2020-02-29 15:45:59

标签: flutter firebase-admob

我无法在测试应用中的设备上显示广告单元。

我正在使用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

如果我使用测试广告provided by 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天前创建的,我是否等待了足够长的时间才能出现?

感谢您的帮助;)

enter image description here

这是我扑扑的医生: enter image description here

2 个答案:

答案 0 :(得分:2)

您正在从admob获得Ad failed to load : 0,这意味着您的代码没有错误,您需要稍等片刻。您的广告ID是新创建的,因此需要一些时间才能从Google服务器获取广告。

如果您的广告不是新创建的,则可能是由于使用错误的Admob Application ID或在某些情况下未将付款信息添加到admob信息中心而引起的。

答案 1 :(得分:0)

供参考,这里是admob错误代码的含义:

  1. 错误代码 0:ERROR_CODE_INTERNAL_ERROR 这表明内部发生了一些事情;例如,一个无效的 收到来自广告服务器的响应。

  2. 错误代码 1:ERROR_CODE_INVALID_REQUEST 广告请求无效;例如,广告单元 ID 不正确。

  3. 错误代码 2:ERROR_CODE_NETWORK_ERROR 广告请求成功,但由于缺少广告没有返回广告 库存。

欲了解更多信息,请访问: https://support.google.com/admob/thread/3494603?hl=en