Unity广告返回INVALID_ARGUMENT

huangapple go评论142阅读模式
英文:

Unity ads returns INVALID_ARGUMENT

问题

我已经在尚未发布的Android应用上集成了UnityAds。
我从服务器的数据库中获取应用ID和广告位ID。
应用ID和广告位ID都是正确的,我已经复制粘贴了大约30次以确保它们正确。
所以,当我尝试在测试模式下获取广告时,它会给我INVALID_ARGUMENT错误。
关于这个错误代码的Unity解释可以在这里找到,但是你可以看到它有点通用。

我有一个表示广告服务的简单对象(类似于admob、FAN、inmobi等)。
在这种情况下,对象被称为advert,以下是如何使用Unity显示广告的示例代码:

protected void showUnity(){
    UnityAds.initialize(this, advert.getApiKey(), true); //advert.getApiKey()返回应用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()返回广告位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(); //我的奖励回调
            } else if (finishState.compareTo(UnityAds.FinishState.SKIPPED) == 0) {
                onAdClosed(); //我的广告关闭回调
            } else if (finishState.compareTo(UnityAds.FinishState.ERROR) == 0) {
                onAdError(finishState.toString()); //我的错误回调
            }
        }

        @Override
        public void onUnityAdsError(UnityAds.UnityAdsError unityAdsError, String s) {
            onAdError(unityAdsError.toString()); //我的错误回调,在这里会得到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

答案1

得分: 3

如果您仔细检查回调函数,您会发现onUnityAdsError有两个参数,第一个参数提供了错误代码,第二个参数为您提供了有关出现问题的信息。

@Override
public void onUnityAdsError(UnityAds.UnityAdsError unityAdsError, String reason) {
    onAdError(unityAdsError.toString()); // 我的错误回调,这里出现INVALID_ARGUMENT错误
}

因此,只需检查原因,您就应该能够找出集成中出现了什么问题。

英文:

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.

答案2

得分: 0

以下是翻译好的内容:

这里有一些方法可以解决INVALID_ARGUMENT问题:

1. 确保在应用程序中实现了正确的初始化代码。有两种类型的初始化:

  1. 仅Unity广告初始化
  2. 中介初始化

这两种方法都有自己的横幅广告、插页式广告和激励式广告代码。

2. 确保将测试模式设置为布尔值。(例如:private Boolean testMode = true;)(在发布到商店之前确保将其设置为false)

3. 您可以将您的手机添加为测试设备,以强制在您的手机上获取测试广告。为此,您首先需要复制设备的广告ID。前往您的手机设置 > Google > 广告 > 此设备的广告标识。复制该标识,然后转到Unity仪表板 > 赚钱 > 测试 > 添加测试设备。在此处添加您设备的广告ID以及任何名称,现在您将能够在该设备上看到测试广告。

英文:

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. (i.e: 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.

huangapple
  • 本文由 发表于 2020年4月5日 00:54:17
  • 转载请务必保留本文链接:https://go.coder-hub.com/61031542.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定