Help Needed for Facebook Audience Network Integration

Hello everyone,
I am integrating Facebook Audience Network in my Android Game.

I am using FAN to load rewarded ad after game start (ASAP) then show it to user when user click a button. Did you used FAN? I have few doubts:

  1. How to verify that user watched full ad and then reward user. Without using Server Side Reward Validation.
    According to FAN Docs for Server Side Reward Validation:
    “This is optional! You don’t have to implement server side reward validation to make use of rewarded video ads. This is only required if you decide to validate rewards on your own server to improve the security by introducing a validation step at your own server. Please provide your publisher end point to your Facebook representative in order to enable this feature.”

  2. Do I need to load ad again after an ad served? or it automatically load itself?

I just hate all Official Docs. And there is absolutely no user generated content I can find in google related to FAN Integration.
Here is official doc:

This is my script so far. But I am not sure if it’s all right. I tested it on Android device and ad is not loading. If someone can please share your complete script for rewarded ad then it will be very helpful.

using UnityEngine.SceneManagement;
using UnityEngine;
using System.Collections;
using AudienceNetwork;

namespace MoreMountains.InfiniteRunnerEngine
{

public class InitializeAdsScript : MonoBehaviour
{
    public GameObject popUpAdFailedToLoad;
    public GameObject checkYourInternet;
    public GameObject popUpAddEnergy;
    public Canvas canvas;
    GameObject mainMenuPage;
    public static bool isEnergyPage = false;


    private RewardedVideoAd rewardedVideoAd;
    private bool isLoaded;
 
    private void Awake()
    {
        AudienceNetworkAds.Initialize();
    }

    void Start()
    {
        DontDestroyOnLoad(this.gameObject);
        DontDestroyOnLoad(canvas);
        LoadRewardedVideo();
    }

    public void LoadRewardedVideo()
    {
        // Create the rewarded video unit with a placement ID (generate your own on the Facebook app settings).
        // Use different ID for each ad placement in your app.
        rewardedVideoAd = new RewardedVideoAd("my placement id"); // Placement ID

        rewardedVideoAd.Register(gameObject);

        // Set delegates to get notified on changes or when the user interacts with the ad.
        rewardedVideoAd.RewardedVideoAdDidLoad = (delegate() {
            Debug.Log("RewardedVideo ad loaded.");
            isLoaded = true;
        });
        rewardedVideoAd.RewardedVideoAdDidFailWithError = (delegate(string error) {
            popUpAdFailedToLoad.SetActive(false);
            Debug.Log("RewardedVideo ad failed to load with error: " + error);
        });
        rewardedVideoAd.RewardedVideoAdWillLogImpression = (delegate() {
            Debug.Log("RewardedVideo ad logged impression.");
        });
        rewardedVideoAd.RewardedVideoAdDidClick = (delegate() {
            Debug.Log("RewardedVideo ad clicked.");
        });

        rewardedVideoAd.RewardedVideoAdDidSucceed = delegate ()
        {
// Rewarding User here. Is this right?
            if(LevelManager.boolAddLife && !(SceneManager.GetActiveScene().name == "LevelSelection"))
            {
                GameManager.Instance.SetLives(3);
            }
            else
            {
                PlayerPrefs.SetInt("TotalEnergyLeft", PlayerPrefs.GetInt("TotalEnergyLeft")+10);
                PlayerPrefs.Save();
            }
            if(SceneManager.GetActiveScene().name == "LevelSelection")
            {
                mainMenuPage.SetActive(true);
            }
            Debug.Log("Rewarded video ad validated by server");
        };

        rewardedVideoAd.RewardedVideoAdDidFail = delegate ()
        {
            popUpAdFailedToLoad.SetActive(true);
            Debug.Log("Rewarded video ad not validated, or no response from server");
        };

        rewardedVideoAd.RewardedVideoAdDidClose = (delegate() {
            Debug.Log("Rewarded video ad did close.");
            if (rewardedVideoAd != null) {
                rewardedVideoAd.Dispose();
            }
        });

        // Initiate the request to load the ad.
        rewardedVideoAd.LoadAd();
    }

    public virtual void OnClickWatchAd()
    {
        if (isLoaded)
        {
            rewardedVideoAd.Show();
            isLoaded = false;
        } else
        {
            checkYourInternet.SetActive(true);
            Debug.Log("Ad not loaded. Click load to request an ad.");
        }
        popUpAddEnergy.SetActive(false);
    }
}
}

That error has a LOT of google responses in the context of FAN. Rather than us googling it for you and laboriously asking you if you have tried each one, let me do it in aggregate: what have you tried from the googling you have already done?

2 Likes

Actually some scripts included in FAN only works in Android device, that’s why I am getting this error in Unity Editor. So, above error not matter now. I am updated my post for updated problems and doubts. Please take a look.

This is usually handled by conditional compilation, to disable code that is not supported:

https://docs.unity3d.com/Manual/PlatformDependentCompilation.html

Fair enough, but not sure what the alternative is. I have not used FAN personally but I know that some people make it work. Perhaps one of them can chime in, or perhaps you can look on the Facebook tech forums for more info.

1 Like

Yeah, Thank you so much for help. I am contacting FAN support. I hope they will solve my problem ASAP.