根据研究,2014 年有一个先前的问题(Is Google adsense available for localhost?)建议添加:
data-adtest="on"
在测试和阅读 comments 之后该解决方案不再有效。在广告单元中:
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- responsive_ad -->
<ins class="adsbygoogle"
style="display:block"
data-ad-client="ca-pub-####"
data-ad-slot="######"
data-ad-format="auto"
data-adtest="on"
data-full-width-responsive="true">
</ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
在 Chrome、Firefox 和 Safari 中进行测试后,会呈现一个白框。搜索后,我无法在产品论坛或任何网站上找到任何解决方案。如何在 localhost 中测试广告单元?
最佳答案
我也试过data-adtest="on"
方法,它也对我不起作用。我发现了两种不同的测试方法:
e. G。这里:https://productforums.google.com/forum/#!msg/adsense/RLeUEq6na-w/i93-TFVRiHUJ
(我自己试过了,对解决方案很满意)
如果您打开了开发者控制台,您会看到出现 403 错误。此处进一步解释了此错误的原因:https://www.shoutmeloud.com/adsense-403-forbidden-error.html .简而言之: Adsense 爬虫拒绝本地主机 .这就是为什么你有一个空白而不是广告。
但如果有第三种方式,我也会很高兴听到它。
关于javascript - 您如何在 localhost 中呈现 Google 广告单元?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54043177/