我正在尝试使用 AdPreview plugin 显示赞助帖子的 AdPreview。我已经创建了 AdGroup 以及相应的 AdCreative,因此我确切地知道需要使用什么 creative_id
/ad_id
来生成预览。
我按照文档所说:
- 加载其插件脚本,并使用
xfbml=1
和appId=<myAppId>
进行初始化 - 在我想要显示预览的位置包含所需的 HTML/XFBML
所以我有这样的:
<body>
<div id="fb-root"></div>
<script>(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/all/xfbml.adpreview.js#xfbml=1&appId=xxxxxxxxxx";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
<!-- other elements -->
<div class="fb-ad-preview" data-creative-id="1234567890" data-page-type="desktopfeed"></div>
<!-- other elements -->
</body>
但是当我加载应该看到此预览呈现的页面时,我只看到 iframe
附加在 .fb-ad-preview
内。该 iframe 指向如下 URL:
http://www.facebook.com/plugins/ad_preview.php?app_id=xxxxxxxxxx&channel=http://static.ak.facebook.com/connect/xd_arbiter/LEdxGgtB9cN.js?version=40#cb=f2a62e0788&domain=www.mycustomdomain.com&origin=http%3A%2F%2Fwww.mycustomdomain.com%3A8000%2Ff12be91bcc&relation=parent.parent&creative_id=1234567890&locale=en_US&page_type=desktopfeed&sdk=joey
它只加载一些绝对不执行任何操作的脚本;甚至根本不抛出错误。
但是,我发现插件页面中的 iframe 有所不同:在插件页面中,在生成的 iframe 的 src
中, channel
查询字符串参数指向 https://s-static.ak.facebook.com
而不是 http://static.ak.facebook.com
。
当我访问原始网址,但将子域更改为 https://s-static.ak.facebook.com
时,会显示一个类似错误的红色框,并显示一条消息 This plugin requires the use of the JavaScript SDK and XFBML.
:/
我的 Facebook 应用程序配置在 www.mycustomdomain.com
和 App domains
中只有 http://www.mycustomdomain.com:8000
(顺便说一句,我正在 python/django 上构建我的 Web 应用程序),并且该应用程序不处于“沙盒”模式。
所以我想知道两件事:
- 首先,为什么该插件对我使用不同的 channel ?
- 为什么它不像插件页面那样渲染 HTML?
我迷路了,有人知道发生了什么事吗?任何帮助将不胜感激,请随时询问我可能遗漏的详细信息。
最佳答案
API 解决方案实际上对我有用,无需指定预览的所有部分。对于以下任何端点,您只需附加 page_type=desktopfeed
(正如文档所说,愚蠢的我)作为查询字符串参数
GET https://graph.facebook.com/{adgroup_id}/previews
GET https://graph.facebook.com/{ad_creative_id}/previews
GET https://graph.facebook.com/act_{adaccount_id}/generatepreviews
您将获得指向实际预览的 iframe 的 HTML 代码:
{
"data": [
{
"body": "<iframe src=\"https://www.facebook.com/ads/api/preview_iframe.php?d=AQLEixbRWLC3D1fEIwqSC69Xs_sCLACoJtNu11HDSPSs_lSkeIrPrtAyxB7HvaPJX5_39KZb1I42Atny-Un3FVRq-6ls_nOp0DtKAhpBndpsFNq0PVb5b1KtjhdkdVrnRSgpPjlrAP2PtJp93u1XNA2QY3pJ_uncMRJPQaSsYjmVFCQ32lp0elUgSEIE8hCoNiEg&t=Adj42KsfL7T-FYEG\" width=\"540\" height=\"450\" scrolling=\"yes\" style=\"border: none;\"></iframe>"
}
]
}
将其嵌入到您想要显示的位置,只需小心浏览器上安装的广告拦截器扩展程序/插件,因为如果 https,它们显然也会阻止此扩展程序/插件://www.facebook.com/ads/api/preview_iframe.php
不在您的白名单中。
无论如何,这是我想要实现的目标的解决方法,但我不会将其标记为我的问题的正确答案,因为该问题仍然存在。
关于javascript - Facebook AdPreview 未呈现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22415866/