简体   繁体   中英

Unity ads returns INVALID_ARGUMENT

I've integrated UnityAds on my Android app (that is not published yet). I get app id and placement id from database on my server. App id and placement id are correct, I've copied and pasted about 30 times for be sure of it. So, when I try to get an ad in test mode, it give me the INVALID_ARGUMENT error. Here an explaination of the error code by Unity, but as you can see it is a little generic.

I have an object that simply represents an ad service (like admob, FAN, inmobi etc) In this case the object is called advert, and here it's how I show an ad with Unity:

protected void showUnity(){
    UnityAds.initialize(this, advert.getApiKey(), true); //advert.getApiKey() returns the app id
    UnityAds.addListener(new IUnityAdsListener() {
        @Override
        public void onUnityAdsReady(String s) {
            Log.i(TAG, "onUnityAdsReady "+s);
            if(s.equals(advert.getUnitId()) && !unityReady)
                UnityAds.show(ActivityAd.this, advert.getUnitId()); //advert.getUnitId() returns the placement id
        }

        @Override
        public void onUnityAdsStart(String s) {
            Log.i(TAG, "onUnityAdsStart "+s);
            unityReady = true;
        }

        @Override
        public void onUnityAdsFinish(String s, UnityAds.FinishState finishState) {
            if (finishState.compareTo(UnityAds.FinishState.COMPLETED) == 0) {
                onAdReward(); //my callback for reward
            } else if (finishState.compareTo(UnityAds.FinishState.SKIPPED) == 0) {
                onAdClosed(); //my callback for ad close
            } else if (finishState.compareTo(UnityAds.FinishState.ERROR) == 0) {
                onAdError(finishState.toString()); //my callback for errors
            }
        }

        @Override
        public void onUnityAdsError(UnityAds.UnityAdsError unityAdsError, String s) {
            onAdError(unityAdsError.toString()); //my callback for errors, here results INVALID_ARGUMENT error
        }
    });
}

Does anyone know what is wrong? Thanks in advance

If you check the callback closely the onUnityAdsError has 2 params, first provides the error code and the second param provides you information about what went wrong.

@Override
public void onUnityAdsError(UnityAds.UnityAdsError unityAdsError, String reason) {
     onAdError(unityAdsError.toString()); //my callback for errors, here results INVALID_ARGUMENT error
}

So just check the reason and you should be able to find out what is going wrong in your integration.

Here are some methods which you can follow to solve this INVALID_ARGUMENT problem

1. Make sure you are implementing the right Initialization code in your app. There are 2 types of Initialization.

  1. Only Unity ads Initialization
  2. Mediation Initialization

and both methods have their own banner, interstitial, and rewarded ad code.

2. Make sure you enable test mode as Boolean. (ie: private Boolean testMode = true;) (make sure to do false this before publish on store)

3. You can add your mobile phone as a test device to get test ads on your phone forcefully. for this, you have to first copy the Ad ID of your device. For that, go to your mobile settings > Google > Ads > This device's advertising ID. copy that ID and go to unity dashboard > Monetization > Testing > Add Test Device. Add your device Ads ID here with any name, and now you will be able to see test ads on the device.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM