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:
-
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.” -
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);
}
}
}