Search code examples
androidfacebookadsinterstitial

FB Ads Error Code: -1 Unknown error - Android Interstitial


I´ve displayed Facebook ads before but today the Interstitial ads stopped working, we I try the debug mode I get an error with code -1 and name Unknown error.

I'm using the following code:

fbInterstitialAd =new com.facebook.ads.InterstitialAd(mContext,id_facebook);
    fbInterstitialAd.setAdListener(new InterstitialAdListener() {
        @Override
        public void onInterstitialDisplayed(Ad ad) {

        }

        @Override
        public void onInterstitialDismissed(Ad ad) {
            adDismissed.run();
        }

        @Override
        public void onError(Ad ad, AdError adError) {
            Log.d("FBads",adError.getErrorMessage());
        }

        @Override
        public void onAdLoaded(Ad ad) {
            adLoaded.run();
        }

        @Override
        public void onAdClicked(Ad ad) {
            adClickedCallback.run();
        }
    });
    fbInterstitialAd.loadAd();

Solution

  • New Facebook SDK Code: Try this Once

    // Declare the InterstitialActivity in AndroidManifest.xml:
    //  <activity android:name="com.facebook.ads.InterstitialAdActivity"
    //            android:configChanges="keyboardHidden|orientation" />
    // In the Activity that will launch the interstitial,
    // implement the AdListener interface and add the following:
    
    import com.facebook.ads.*;
    
    private InterstitialAd interstitialAd;
    
    private void loadInterstitialAd() {
        interstitialAd = new InterstitialAd(this, "id_facebook");
        interstitialAd.setAdListener(this);
        interstitialAd.loadAd();
    }
    
    @Override
    public void onError(Ad ad, AdError error) {
        // Ad failed to load
    }
    
    @Override
    public void onAdLoaded(Ad ad) {
        // Ad is loaded and ready to be displayed
        // You can now display the full screen add using this code:
        interstitialAd.show();
    }