简体   繁体   English

Unity 广告返回 INVALID_ARGUMENT

[英]Unity ads returns INVALID_ARGUMENT

I've integrated UnityAds on my Android app (that is not published yet).我已经在我的 Android 应用程序(尚未发布)上集成了 UnityAds。 I get app id and placement id from database on my server.我从服务器上的数据库中获取应用程序 ID 和放置 ID。 App id and placement id are correct, I've copied and pasted about 30 times for be sure of it. App id 和placement id 是正确的,我已经复制并粘贴了大约30 次以确保这一点。 So, when I try to get an ad in test mode, it give me the INVALID_ARGUMENT error.因此,当我尝试在测试模式下获取广告时,它给了我 INVALID_ARGUMENT 错误。 Here an explaination of the error code by Unity, but as you can see it is a little generic. 是 Unity 对错误代码的解释,但您可以看到它有点通用。

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:我有一个 object,它仅代表一个广告服务(如 admob、FAN、inmobi 等)在这种情况下,object 被称为广告,这里是如何展示广告:

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.如果您仔细检查回调,onUnityAdsError 有 2 个参数,第一个提供错误代码,第二个参数提供有关出错的信息。

@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这里有一些方法可以用来解决这个 INVALID_ARGUMENT 问题

1. Make sure you are implementing the right Initialization code in your app. 1.确保你在你的应用中实现了正确的初始化代码。 There are 2 types of Initialization.有两种类型的初始化。

  1. Only Unity ads Initialization仅 Unity 广告初始化
  2. Mediation Initialization中介初始化

and both methods have their own banner, interstitial, and rewarded ad code.这两种方法都有自己的横幅、插页式和奖励广告代码。

2. Make sure you enable test mode as Boolean. 2.确保启用测试模式为 Boolean。 (ie: private Boolean testMode = true;) (make sure to do false this before publish on store) (即:私有 Boolean testMode = true;)(确保在商店发布之前做假)

3. You can add your mobile phone as a test device to get test ads on your phone forcefully. 3.您可以将您的手机添加为测试设备,以便在您的手机上强制获取测试广告。 for this, you have to first copy the Ad ID of your device.为此,您必须先复制设备的广告 ID。 For that, go to your mobile settings > Google > Ads > This device's advertising ID.为此,go 到您的移动设置 > Google > 广告 > 此设备的广告 ID。 copy that ID and go to unity dashboard > Monetization > Testing > Add Test Device.将该 ID 和 go 复制到统一仪表板 > 货币化 > 测试 > 添加测试设备。 Add your device Ads ID here with any name, and now you will be able to see test ads on the device.在此处添加您的设备广告 ID 并使用任何名称,现在您将能够在设备上看到测试广告。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 跟进意图更新时出现Dialogflow INVALID_ARGUMENT错误 - Dialogflow INVALID_ARGUMENT error on followup intent update Google Dataflow / Dataprep Shuffle键太大(INVALID_ARGUMENT) - Google Dataflow / Dataprep Shuffle key too large (INVALID_ARGUMENT) 使用 IamCredentialsClient 对 Blob 进行签名时的 INVALID_ARGUMENT 响应 - INVALID_ARGUMENT response when signingBlob using IamCredentialsClient Apache Beam With GCP Dataflow 抛出 INVALID_ARGUMENT - Apache Beam With GCP Dataflow throws INVALID_ARGUMENT Google DocumentAI Java 示例因 io.grpc.StatusRuntimeException 失败:INVALID_ARGUMENT:请求包含无效参数 - Google DocumentAI Java example fails with io.grpc.StatusRuntimeException: INVALID_ARGUMENT: Request contains an invalid argument “错误”:{“代码”:400,“消息”:“ RecognitionAudio未设置。”,“状态”:“ INVALID_ARGUMENT”}} - “error”: { “code”: 400, “message”: “RecognitionAudio not set.”, “status”: “INVALID_ARGUMENT” } } 尝试使用Google Cloud Vision时出现INVALID_ARGUMENT - I get INVALID_ARGUMENT when I try to use Google Cloud Vision Simba][SpannerJDBCDriver](100300) 来自服务器的错误消息:INVALID_ARGUMENT:不支持位置参数 - Simba][SpannerJDBCDriver](100300) Error message from server: INVALID_ARGUMENT: Positional parameters are not supported 通过 Java API 创建 Google Cloud Function:“io.grpc.StatusRuntimeException: INVALID_ARGUMENT” - Creating Google Cloud Function via Java API: “io.grpc.StatusRuntimeException: INVALID_ARGUMENT” gcloud app deploy 命令错误 INVALID_ARGUMENT:此运行时需要 WEB-INF/appengine-web.xml - gcloud app deploy command error INVALID_ARGUMENT: WEB-INF/appengine-web.xml is required for this runtime
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM