5

I've been trying to get AdMob to work for some time on my app. I keep getting onFailedToRecieveAd(Invalid Ad Request) message in the log. I've paired down my test application to this:

  AdView adView;
   LinearLayout ll;

   public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
    adView = new AdView(this, AdSize.BANNER, "pub-2...............");//inserted my 16 digit pub id here
    adView.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL);

    ll = new LinearLayout(this);  
    ll.setOrientation(LinearLayout.VERTICAL);  

    ll.addView(adView); 
    setContentView(ll); 
    AdRequest adRequest = new AdRequest();

    adRequest.addTestDevice("3...............");// 16 digits, tried other strings as 
   // follows:

   //for addTestDevice I've tried several numbers, including the 16 digit device
  // number given me by my "device id" application, the "0123456789ABCDEF" device number
  // given by my console and device windows, the "CECE.........................." 32 digit
 // device number my logcat file told me to use in a logcat message, 
  //  "AdRequest.TEST_EMULATOR"
  // which an admob example in the docs said to use, "9774d56d682e549c" which another 
  //  admob docs example said to use.

     adView.loadAd(adRequest);

I've also tried adView.loadAd(new AdRequest()); using no device id as in another one of the google admob example apps.

nothing has worked to show anything, it's not even creating space for the ad, just the onFailedToRecieveAd(Invalid Ad Request) message in the logcat

I've also included the necessary permissions and "com.google.ads.AdActivity" in the manifest.

4

4 回答 4

14

哇,经过几天的挫折和各种论坛的帖子,我找到了答案。

您必须在 Admob 网站上访问您的帐户,为 admob 广告设置您的特定应用,并获得一个新的更长的发布商编号。我的出版商编号仅以“pub-......”开头,而我的新编号较长,并以“ca-app-pub-.......”开头。当我在示例横幅应用程序中看到“ca-app-pub”前言时,我从一开始就对此感到好奇。

“横幅广告 1”说明中的 Google Admob“Google 移动广告 SDK”开发站点上的任何位置(https://developers.google.com/mobile-ads-sdk/docs/admob/fundamentals?hl=en_US#android)它是否提到必须返回您的 admob 帐户来设置您的特定广告应用程序并获取新的发布商编号。

愚蠢的错误是最难改正的。

于 2013-08-28T18:43:03.870 回答
3

id要小心,有2个代码:编辑号(像这样:pub-xxxxxxxxxxxxxxxx),另一个是banner id(像这样:ca-app-pub-xxxxxxxxxxxxxxxx/xxxxxxxxxx)(这个你需要使用)

你需要使用最后一个,如果你使用第一个不起作用:)

于 2014-05-06T15:52:17.677 回答
1

收到广告失败并不罕见。这是一条正常的消息,本质上是说此时您的应用没有广告可投放。

这意味着您的 Admob 集成正在运行,您正在从服务器获得响应。随着您的应用发送更多请求,它将更有可能获得广告展示。

于 2013-08-28T01:16:15.347 回答
0

您是否尝试过在不设置测试设备 ID 的情况下请求广告?

adView.loadAd(new AdRequest());

尝试添加以下代码行以获取有关失败的更多信息:

// Set AdListener
adView.setAdListener(new AdListener() {
    @Override
    public void onFailedToReceiveAd(Ad ad, ErrorCode error) {
        System.err.println("Ad failed: " + ad.toString() + error.toString());    
    }

    @Override
    public void onReceiveAd(Ad ad) {
        System.out.println("Ad received: " + ad.toString());
    }
});
于 2013-08-27T14:38:11.877 回答