B4A Library Facebook Audience Network Library

Original library: https://developers.facebook.com/docs/audience-network/guides/adding-sdk/android
Based on Android Audience Network SDK 6.5.0 (17 May 2021)
Banner, Interstitial and Rewarded Video.

Library does not work anymore as Facebook ads must be served thorough mediation partners.
More info HERE.

FBAudienceNetworkAds

Author:
Author: Facebook - B4a Wrapper: Pendrush
Version: 6.50
  • FBAudienceNetworkBanner
    • Events:
      • AdClicked
      • AdError (Error As String)
      • AdLoaded
      • AdLoggingImpression
    • Fields:
      • AD_BANNER_HEIGHT_50 As Object
        Banner - 50dip height, you need to set parent view height to 50dip
      • AD_BANNER_HEIGHT_90 As Object
        Banner - 90dip height, you need to set parent view height to 90dip
      • AD_RECTANGLE_HEIGHT_250 As Object
        Rectangle - 250dip height, you need to set parent view height to 250dip
    • Functions:
      • BringToFront
      • DestroyAd
        Destroy Ad
      • Initialize (arg1 As String)
      • InitializeBanner (EventName As String, PlacementId As String, Country As Int, State As Int, BannerAdSize As com.facebook.ads.AdSize)
        Initialize Banner Ad
        AdBanner.InitializeBanner("AdBanner", "IMG_16_9_APP_INSTALL#YOUR_PLACEMENT_ID", 0, 0, AdFacebook.AD_BANNER_HEIGHT_50)
        Activity.AddView(AdBanner, 0, 0, 100%x, 50dip)
        AdBanner.LoadAd
      • Invalidate
      • Invalidate2 (arg0 As android.graphics.Rect)
      • Invalidate3 (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int)
      • IsInitialized As Boolean
      • LoadAd
        Load Ad
      • RemoveView
      • RequestFocus As Boolean
      • SendToBack
      • SetBackgroundImage (arg0 As android.graphics.Bitmap) As BitmapDrawable
      • SetColorAnimated (arg0 As Int, arg1 As Int, arg2 As Int)
      • SetLayout (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int)
      • SetLayoutAnimated (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int, arg4 As Int)
      • SetVisibleAnimated (arg0 As Int, arg1 As Boolean)
    • Properties:
      • Background As android.graphics.drawable.Drawable
      • Color As Int [write only]
      • Enabled As Boolean
      • Height As Int
      • Left As Int
      • Padding As Int()
      • Parent As Object [read only]
      • Tag As Object
      • Top As Int
      • Visible As Boolean
      • Width As Int
  • FBAudienceNetworkInterstitial
    • Events:
      • AdClicked
      • AdDismissed
      • AdDisplayed
      • AdError (Error As String)
      • AdLoaded
      • AdLoggingImpression
    • Functions:
      • DestroyAd
        Destroy Ad.
      • InitializeInterstitialAd (EventName As String, PlacementId As String, Country As Int, State As Int)
        Initialize Interstitial Ad
        AdInterstitial.InitializeInterstitialAd("AdInterstitial", "IMG_16_9_APP_INSTALL#YOUR_PLACEMENT_ID", 0, 0)
        AdInterstitial.LoadAd
      • IsAdInvalidated As Boolean
        Check if Ad is already expired or invalidated,
        and do not show Ad if that is the case.
        You will not get paid to show an invalidated Ad.
      • IsAdLoaded As Boolean
        Check if Ad is loaded.
      • IsInitialized As Boolean
      • LoadAd
        Load Ad.
      • ShowAd
        Show Ad.
  • FBAudienceNetworkRewardedVideo
    • Events:
      • AdClicked
      • AdError (Error As String)
      • AdLoaded
      • AdLoggingImpression
      • AdRewardedVideoClosed
      • AdRewardedVideoCompleted
    • Functions:
      • DestroyAd
        Destroy Ad.
      • InitializeRewardedVideoAd (EventName As String, PlacementId As String, Country As Int, State As Int)
        Initialize Rewarded Video Ad
        AdRewardedVideo.InitializeRewardedVideoAd("AdRewardedVideo", "VID_HD_16_9_15S_LINK#YOUR_PLACEMENT_ID", 0, 0)
        AdRewardedVideo.LoadAd
      • IsAdInvalidated As Boolean
        Check if Ad is already expired or invalidated,
        and do not show Ad if that is the case.
        You will not get paid to show an invalidated Ad.
      • IsAdLoaded As Boolean
        Check if Ad is loaded.
      • IsInitialized As Boolean
      • LoadAd
        Load Ad.
      • ShowAd
        Show Ad.


For InterstitialAd and for RewardedVideoAd you need to add this in your manifest:
B4X:
AddApplicationText(<activity
            android:name="com.facebook.ads.AudienceNetworkActivity"
            android:configChanges="keyboardHidden|orientation|screenSize"
            android:exported="false"
            android:theme="@android:style/Theme.Translucent.NoTitleBar" />
        <provider
            android:name="com.facebook.ads.AudienceNetworkContentProvider"
            android:authorities="${applicationId}.AudienceNetworkContentProvider"
            android:exported="false" />)


Download library zip file from this link and extract archive to Additional Libraries folder. I'm not able to upload on forum, as size of file is over maximum allowed limit.

v6.00 - Manifest code changed.
v0.98+ - bring some breaking changes on Initialize method to support CCPA. Please check country and state parameters on Facebook (data processing options for CCPA)
 

Attachments

  • FBAudienceNetworkExample.zip
    16.9 KB · Views: 201
Last edited:

Pendrush

Well-Known Member
Licensed User
I don't have any experience with them.
You can't receive payment in every country, my country for example is not supported for payout, also app need to pass Facebook quality check.
As I found on reddit, for USA audience, audience network pays more for about 150% then admob.
You can check if your country is supported and try it in some of your apps.
Also, no ads if user is not logged in phone's Facebook app. Even test ad wont work.
 
Last edited:

Douglas Farias

Expert
Licensed User
Hi @Pendrush.
i m testing your example, thx for this.

i created a facebook audience account, completed my registration, added an app, it was approved, copied the banner and interstitial code and changed it in your example.

AdBanner.InitializeBanner ("AdBanner", "IMG_16_9_APP_INSTALL # YOUR_PLACEMENT_ID", AdBanner.AD_BANNER_HEIGHT_50)

I put my generated and it was something like that
AdBanner.InitializeBanner ("AdBanner", "IMG_16_9_APP_INSTALL # 291069155609476_29111..........", AdBanner.AD_BANNER_HEIGHT_50)

however the displayed ad is always the same
Facebook Test ad (install)
a real announcement is not shown, only the facebook test announcement.

my package name is correct, the banner code is correct, there are no errors, I have facebook installed and logged in, I really couldn't make your example work.

on the log show
Ad Loaded fired
Ad Logging Impression fired

Would you have any tips?

thank you
 

Attachments

  • WhatsApp Image 2020-06-19 at 16.11.57.jpeg
    WhatsApp Image 2020-06-19 at 16.11.57.jpeg
    53.6 KB · Views: 175

Pendrush

Well-Known Member
Licensed User
I'm not using Facebook Audience Network for my self, so I cant tell you for sure what could be.
I think error is here IMG_16_9_APP_INSTALL # 291069155609476_29111..........
PlacementID should be like 291069155609476_29111..... without IMG_16_9_APP_INSTALL # part.
"IMG_16_9_APP_INSTALL # " is used for test Ads only.
 

rubelrahman

New Member
Thanks for nice library, Working great. Is there any way to show ad to non loggedin user device.
Advance thanks for your kind co-operation..
 

madrigal

Member
Is there anyone who started making any profit from facebook using this library? because the testing worked with me but when im put the app on live mode it showed as if there are requests but there are no impressions so the ads did not show live, and its gave me a "no fill" error , does anyone have an idea about this problem and how to solve it ?
 
Top