7

Background

I had this on the project, to handle Facebook ads via Admob:

implementation 'com.google.ads.mediation:facebook:6.11.0.0'

And in code:

final AdRequest.Builder builder = new AdRequest.Builder();
builder.addNetworkExtrasBundle(FacebookAdapter.class, new FacebookExtras().setNativeBanner(true).build());
adLoader.loadAd(builder.build());

It works fine.

The problem

Now when updating to the new version (originally I asked about 6.12.0) :

implementation 'com.google.ads.mediation:facebook:6.14.0'

It shows that both FacebookAdapter and FacebookExtras don't exist anymore.

What I've tried

Checking on the docs, even though they say to use this version, the code they tell to use is the same as before:

Bundle extras = new FacebookExtras()
       .setNativeBanner(true)
       .build();

AdManagerAdRequest request =  new AdManagerAdRequest.Builder()
       .addNetworkExtrasBundle(FacebookAdapter.class, extras)
       .build();

EDIT: someone wrote that I should use this, but without any explanation of where he got this from, and I also failed to find the origin of it:

enter image description here

I tried to ask some questions about it, but then it got removed.

EDIT: It seems that the old instructions are now completely gone.

So perhaps it's not needed anymore:

https://developers.google.com/admob/android/mediation/meta#using_facebook_native_ads_without_a_mediaview

Then again, they still mention there the class that doesn't exist anymore : FacebookAdapter .

I tried to just update the dependency and remove the code that can't be used, but then I got this error while loading the native ad:

error code 3 - Unable to instantiate mediation adapter class.

The question

What should I use instead? How come it's not documented?

android developer
  • 114,585
  • 152
  • 739
  • 1,270

3 Answers3

0

I think the documentation only added more information logs, and that now the minimal that we need is just to have the dependencies and that's it.

If I'm wrong, please let me know.

Sadly though, I still have the error, but I think the reason is something on the website/s (Facebook and/or Admob)

android developer
  • 114,585
  • 152
  • 739
  • 1,270
0

I've done a bit of research on the subject, I'd venture to guess that the documentation related to the FacebookMediationAdapter is in the process of being updated, and the answers given earlier were AI-generated, which is why you couldn't find these classes.

I also examined FacebookAdapter.java in version 6.11.0.0, it contains the following log: "Facebook waterfall mediation is deprecated and will be removed in a future adapter version. Please update to serve bidding ads instead. See link for more information."

Also, the documentation mentions: "Audience Network is now only using bidding to fill ads in iOS and Android apps. You’ll need to move your apps from waterfall to bidding to monetize with Audience Network."

I can assume (but this is not a fact) that FacebookAdapter was removed due to its integration with waterfall.

I think we need to wait for an answer to your question from the Google team, this will be the most reputable source of the answer

At the moment I see a workaround when using native elements - use the Audience Network SDK.

You should initialize the Audience Network SDK:

public class YourApplication extends Application {
    ...
    @Override
    public void onCreate() {
        super.onCreate();
        // Initialize the Audience Network SDK
        AudienceNetworkAds.initialize(this);       
    }
    ...
}

Then, instantiate a NativeBannerAd object, create an AdListener, and call loadAd(...) in your Activity:

public class NativeBannerAdActivity extends Activity {

    private final String TAG = NativeBannerAdActivity.class.getSimpleName();
    private NativeBannerAd nativeBannerAd;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // Instantiate a NativeBannerAd object. 
        // NOTE: the placement ID will eventually identify this as your App, you can ignore it for
        // now, while you are testing and replace it later when you have signed up.
        // While you are using this temporary code you will only get test ads and if you release
        // your code like this to the Google Play your users will not receive ads (you will get a no fill error).
        nativeBannerAd = new NativeBannerAd(this, "YOUR_PLACEMENT_ID");
        NativeAdListener nativeAdListener = new NativeAdListener() {

            @Override
            public void onMediaDownloaded(Ad ad) {
                // Native ad finished downloading all assets
                Log.e(TAG, "Native ad finished downloading all assets.");
            }

            @Override
            public void onError(Ad ad, AdError adError) {
                // Native ad failed to load
                Log.e(TAG, "Native ad failed to load: " + adError.getErrorMessage());
            }

            @Override
            public void onAdLoaded(Ad ad) {
                // Native ad is loaded and ready to be displayed
                Log.d(TAG, "Native ad is loaded and ready to be displayed!");
            }

            @Override
            public void onAdClicked(Ad ad) {
                // Native ad clicked
                Log.d(TAG, "Native ad clicked!");
            }

            @Override
            public void onLoggingImpression(Ad ad) {
                // Native ad impression
                Log.d(TAG, "Native ad impression logged!");
            }
        });
        // load the ad
        nativeBannerAd.loadAd(
                nativeBannerAd.buildLoadAdConfig()
                        .withAdListener(nativeAdListener)
                        .build());
    }
}

You may find the following resources related to use the Google Mobile Ads SDK with Meta Audience Network using mediation helpful:

  • Here you can see the mediation example and adapters for mediating via the Google Mobile Ads SDK

  • On this page you can see information on how you can independently build a mediation adapter for ad networks

  • Also, I found an issue that confirms that in September 2022 Meta made some improvements. This error was also related to the FacebookMediationAdapter.

Hope some of this can help you

Victor Sklyarov
  • 827
  • 2
  • 3
  • 24
  • So still no idea what I'm supposed to do? It also mentions "KEY_SOCIAL_CONTEXT_ASSET" , but doesn't explain what it is and what I'm supposed to do with it (except that maybe it's a string) : https://developers.google.com/admob/android/mediation/meta#native_ads – android developer Aug 02 '23 at 07:38
  • The `KEY_SOCIAL_CONTEXT_ASSET` itself is simply the `"social_context"` string, which is the key to extract the value of another string into the `socialContext` variable. I searched for hints on this topic on Github, and found several repositories that use this key in the code. All I found was [this react-native repository](https://github.com/NZME/react-native-ad-manager/blob/8baa226063d6e3607f2fc9597d429814055a59ae/android/src/main/java/com/matejdr/admanager/NativeAdViewContainer.java#L567), multiple forks of that repo, and one unique repo where the value was being retrieved but never used. – Victor Sklyarov Aug 02 '23 at 12:46
  • I don't understand what it means. It was written in the paragraph talking about incorrect mapping for the binding of the native ads of Facebook... – android developer Aug 02 '23 at 13:32
  • As I understood from the documentation, this string is passed to the custom user's adapter and contains everything that "don't map one-to-one to Google native ad assets". Thus, you need to independently correlate the assets in this line with Google native ad assets if they don't map because of something. – Victor Sklyarov Aug 02 '23 at 14:34
  • But where can I read about how to use this string? And, if Google know about it, why don't they work accordingly ? – android developer Aug 02 '23 at 14:58
  • Unfortunately, I don't know why Google didn't provide this information... Perhaps the documentation is being updated. At the moment, I see only one option that you can try - print the given string, research its structure, and try to correlate the elements with each other... First, we need to see what this string represents. – Victor Sklyarov Aug 02 '23 at 15:23
  • OK thank you. The only place here that asks about it still has no answer, and the person even thinks it might not even be a string: https://stackoverflow.com/questions/70988558/hot-to-integrate-metafacebook-audience-network-binding-with-admob – android developer Aug 02 '23 at 18:56
  • About `KEY_SOCIAL_CONTEXT_ASSET`, I've got some data about it (reported via Crashlytics). It seems that for most cases, it's a website URL (though all letters are in upper-case, example: "UNIPOLHOME.IT") . In other cases, it's just a message, such as "FREE · Open in app" . So, this could fit in sub-title text, if it's not available... – android developer Aug 03 '23 at 06:28
  • Is there only a value in this line, or is the key also there? For example, `"url"="UNIPOLHOME.IT"` or `"subtitle"="FREE · Open in app"`? If there is a key, then it is easier to parse this string and correlate the parts with Google native ad assets, if there are no keys, then it is more complicated, and you need to determine the type of context first. – Victor Sklyarov Aug 03 '23 at 09:35
  • No, it's just what I wrote. A simple string containing exactly what I wrote. There is no "type" here. It's all just a simple string. What I wrote is that perhaps you can use it in case you don't have the normal data. – android developer Aug 03 '23 at 09:49
0

In the dependency com.google.ads.mediation:facebook:6.14.0.0, the class FacebookAdapter and FacebookExtras have been deprecated. You should replace them with the following alternatives:

FacebookAdapter: Use FacebookBiddingAdapter instead. FacebookExtras: Use FacebookBiddingExtraBundleBuilder instead. These alternatives are provided to ensure compatibility and to incorporate the latest updates and features from the Facebook Audience Network SDK.

Make sure to update your code accordingly and replace the deprecated classes with their respective alternatives to ensure smooth integration and functionality with the Facebook mediation adapter.