2

I cannot display my ad unit on my device in test app.

I'am using the firebase_admob 0.9.1+1 plugin

This is the code I use :

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
  );

}

Here is the log I get :

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

So I specified the ID of my device like this:

  MobileAdTargetingInfo targetingInfo = MobileAdTargetingInfo(
    nonPersonalizedAds: true,
    testDevices: <String>["6C11832B439BDE4C399171C8D4CC6515"],
  );

But the ad still doesn't appear. Here is the log I get :

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

If I use a test advertisement provided by Google, the advertisement works well and here is the log I get:

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

What's wrong with my ad unit? I created it 2 days ago, did I wait long enough for it to appear?

Thanks for your help ;)

enter image description here

Here is my flutter doctor : enter image description here

fli27
  • 329
  • 1
  • 6
  • 18

2 Answers2

6

You are getting Ad failed to load : 0 from admob which means there is no fault in your code and you need to wait a little. Your ad id is newly created so it will take some time to fetch ads from google servers.

If your ad is not newly created then the error might be from using a bad Admob Application ID or in some cases not adding payment information to your admob dashboard.

Payam Asefi
  • 2,677
  • 2
  • 15
  • 26
  • 1
    Hello, a few minutes before your answer I configured the payment information (which I did not actually do) Now I have another error : `Ad failed to load: 3` – fli27 Feb 29 '20 at 22:03
  • @magikbibi take a look at [this](https://stackoverflow.com/a/33712905/1656813) answer – Payam Asefi Feb 29 '20 at 23:59
  • Hello I just waited a few hours after configuring my payment for the ad units to appear. – fli27 Mar 01 '20 at 08:13
0

For the reference, here are the meaning of admob error codes :

  1. Error Code 0 : ERROR_CODE_INTERNAL_ERROR This indicates that something happened internally; for instance, an invalid response was received from the ad server.

  2. Error Code 1 : ERROR_CODE_INVALID_REQUEST The ad request was invalid; for instance, the ad unit ID was incorrect.

  3. Error Code 2 : ERROR_CODE_NETWORK_ERROR The ad request was successful, but no ad was returned due to lack of ad inventory.

For more information , visit : https://support.google.com/admob/thread/3494603?hl=en