0

根据 facebook 的文档,我可以通过以下请求获得我的广告的 HTML 预览片段:

https://graph.facebook.com/CREATIVE_ID/previews?accesstoken=MY_ACCESS_TOKEN  

所以我做到了,我得到了这个:

{
  "data": [
    {
      "body": "<div class=\"unclickable\"><div><div class=\"_4u8\" data-ad=\"&#123;&quot;adid&quot;:6010408139346,&quot;segment&quot;:&quot;market&quot;&#125;\" id=\"6010408139346-id_518a13accaf072305181220\"><div class=\"_24n fbEmuStreamStory fbEmuMarketplace\"><div class=\"clearfix\"><a class=\"_24x _8o _8s lfloat\" onclick=\"new LegacyContextualDialog().init(HTML(&quot;\\u003Cdiv class=\\&quot;pam\\&quot;&gt;\\u003Cdiv class=\\&quot;mbs fwb\\&quot;&gt;Linkable Area\\u003C\\/div&gt;The photo and name of the viewer&#039;s friend link to the friend&#039;s profile. \\u003Ca target=\\&quot;_blank\\&quot; href=\\&quot;http:\\/\\/www.facebook.com\\/pligor\\&quot;&gt;preview\\u003C\\/a&gt;\\u003C\\/div&gt;&quot;)).setWidth(300).setContext(this).enableBehavior(LayerHideOnBlur).disableBehavior(LayerDestroyOnHide).show();\" tabindex=\"-1\" aria-hidden=\"true\"><img class=\"_s0 _54ru img\" src=\"https://fbcdn-profile-a.akamaihd.net/hprofile-ak-ash3/c6.5.64.64/s32x32/64971_487308981311280_695242760_t.jpg\" alt=\"\" /></a><div class=\"_42ef\"><div class=\"fbEmuMainBody\"><span class=\"uiStream\"><h5 class=\"uiStreamMessage\"><div class=\"actorDescription\"><span class=\"actorName\"><a class=\"actorName firstName _24x\" onclick=\"new LegacyContextualDialog().init(HTML(&quot;\\u003Cdiv class=\\&quot;pam\\&quot;&gt;\\u003Cdiv class=\\&quot;mbs fwb\\&quot;&gt;Linkable Area\\u003C\\/div&gt;The photo and name of the viewer&#039;s friend link to the friend&#039;s profile. \\u003Ca target=\\&quot;_blank\\&quot; href=\\&quot;http:\\/\\/www.facebook.com\\/pligor\\&quot;&gt;preview\\u003C\\/a&gt;\\u003C\\/div&gt;&quot;)).setWidth(300).setContext(this).enableBehavior(LayerHideOnBlur).disableBehavior(LayerDestroyOnHide).show();\">George Pligor</a><i class=\"mhs img sp_5t1i4q sx_c8ea4c\"></i><a class=\"actorName _24x\" onclick=\"new LegacyContextualDialog().init(HTML(&quot;\\u003Cdiv class=\\&quot;pam\\&quot;&gt;\\u003Cdiv class=\\&quot;mbs fwb\\&quot;&gt;Linkable Area\\u003C\\/div&gt;This page\\/application icon and name link to the page\\/application. \\u003Ca target=\\&quot;_blank\\&quot; href=\\&quot;http:\\/\\/www.facebook.com\\/AndroidDevelopersDiscussion?ref=stream\\&quot;&gt;preview\\u003C\\/a&gt;\\u003C\\/div&gt;&quot;)).setWidth(300).setContext(this).enableBehavior(LayerHideOnBlur).disableBehavior(LayerDestroyOnHide).show();\">Android Developers</a></span></div> <div class=\"messageBody\"><div class=\"whitespaceLink\" id=\"u_0_0\"><a class=\"_24x\" onclick=\"new LegacyContextualDialog().init(HTML(&quot;\\u003Cdiv class=\\&quot;pam\\&quot;&gt;\\u003Cdiv class=\\&quot;mbs fwb\\&quot;&gt;Linkable Area\\u003C\\/div&gt;Users who click this area will link to the destination specified by this ad. \\u003Ca target=\\&quot;_blank\\&quot; href=\\&quot;\\/AndroidDevelopersDiscussion\\/posts\\/533162160059295\\&quot;&gt;preview\\u003C\\/a&gt;.\\u003C\\/div&gt;&quot;)).setWidth(300).setContext(this).enableBehavior(LayerHideOnBlur).disableBehavior(LayerDestroyOnHide).show();\" id=\"u_0_1\"></a>Is this for real?!<br /> <a class=\"_24x\" target=\"_blank\" rel=\"nofollow\" onclick=\"new LegacyContextualDialog().init(HTML(&quot;\\u003Cdiv class=\\&quot;pam\\&quot;&gt;\\u003Cdiv class=\\&quot;mbs fwb\\&quot;&gt;Linkable Area\\u003C\\/div&gt;This clicks through to the webpage liked by the user. \\u003Ca target=\\&quot;_blank\\&quot; href=\\&quot;http:\\/\\/www.facebook.com\\/l.php?u=http\\u00253A\\u00252F\\u00252Fstackoverflow.com\\u00252Fquestions\\u00252F16385364\\u00252Fwhen-an-activity-binds-an-already-binded-service-the-onrebind-gets-the-old-inten&amp;amp;h=rAQHUwtZv&amp;amp;s=1\\&quot; rel=\\&quot;nofollow\\&quot; onmouseover=\\&quot;LinkshimAsyncLink.swap(this, &amp;quot;http:\\\\\\/\\\\\\/stackoverflow.com\\\\\\/questions\\\\\\/16385364\\\\\\/when-an-activity-binds-an-already-binded-service-the-onrebind-gets-the-old-inten&amp;quot;);\\&quot; onclick=\\&quot;LinkshimAsyncLink.referrer_log(this, &amp;quot;http:\\\\\\/\\\\\\/stackoverflow.com\\\\\\/questions\\\\\\/16385364\\\\\\/when-an-activity-binds-an-already-binded-service-the-onrebind-gets-the-old-inten&amp;quot;, &amp;quot;http:\\\\\\/\\\\\\/www.facebook.com\\\\\\/si\\\\\\/ajax\\\\\\/l\\\\\\/render_linkshim_log\\\\\\/?u=http\\\\u00253A\\\\u00252F\\\\u00252Fstackoverflow.com\\\\u00252Fquestions\\\\u00252F16385364\\\\u00252Fwhen-an-activity-binds-an-already-binded-service-the-onrebind-gets-the-old-inten&amp;amp;h=rAQHUwtZv&amp;amp;s=1&amp;quot;);\\&quot;&gt;preview\\u003C\\/a&gt;\\u003C\\/div&gt;&quot;)).setWidth(300).setContext(this).enableBehavior(LayerHideOnBlur).disableBehavior(LayerDestroyOnHide).show();\"><span>http://stackoverflow.com/</span><wbr /><span class=\"word_break\"></span><span>questions/16385364/</span><wbr /><span class=\"word_break\"></span>when-an-activity-binds-an-a</a><a class=\"_24x\" onclick=\"new LegacyContextualDialog().init(HTML(&quot;\\u003Cdiv class=\\&quot;pam\\&quot;&gt;\\u003Cdiv class=\\&quot;mbs fwb\\&quot;&gt;Linkable Area\\u003C\\/div&gt;Users who click this area will link to the destination specified by this ad. \\u003Ca target=\\&quot;_blank\\&quot; href=\\&quot;\\/AndroidDevelopersDiscussion\\/posts\\/533162160059295\\&quot;&gt;preview\\u003C\\/a&gt;.\\u003C\\/div&gt;&quot;)).setWidth(300).setContext(this).enableBehavior(LayerHideOnBlur).disableBehavior(LayerDestroyOnHide).show();\">...</a></div></div></h5></span><div class=\"whitespaceLink\" id=\"u_0_2\"><a class=\"_24x\" onclick=\"new LegacyContextualDialog().init(HTML(&quot;\\u003Cdiv class=\\&quot;pam\\&quot;&gt;\\u003Cdiv class=\\&quot;mbs fwb\\&quot;&gt;Linkable Area\\u003C\\/div&gt;Users who click this area will link to the destination specified by this ad. \\u003Ca target=\\&quot;_blank\\&quot; href=\\&quot;\\/AndroidDevelopersDiscussion\\/posts\\/533162160059295\\&quot;&gt;preview\\u003C\\/a&gt;.\\u003C\\/div&gt;&quot;)).setWidth(300).setContext(this).enableBehavior(LayerHideOnBlur).disableBehavior(LayerDestroyOnHide).show();\" id=\"u_0_3\"></a><div class=\"mvs plm fbEmuStreamAttachment fbEmuStreamAttachmentOffset textOnly fbEmuStreamBaseStory fbEmuStreamBaseStory\"><a class=\"fbEmuStreamTitle _24x fbEmuStreamLink\" onclick=\"new LegacyContextualDialog().init(HTML(&quot;\\u003Cdiv class=\\&quot;pam\\&quot;&gt;\\u003Cdiv class=\\&quot;mbs fwb\\&quot;&gt;Linkable Area\\u003C\\/div&gt;Users who click this area will link to the destination specified by this ad. \\u003Ca target=\\&quot;_blank\\&quot; href=\\&quot;http:\\/\\/www.facebook.com\\/l.php?u=http\\u00253A\\u00252F\\u00252Fstackoverflow.com\\u00252Fquestions\\u00252F16385364\\u00252Fwhen-an-activity-binds-an-already-binded-service-the-onrebind-gets-the-old-inten&amp;amp;h=XAQE9ndNZ&amp;amp;s=1\\&quot; rel=\\&quot;nofollow\\&quot; onmouseover=\\&quot;LinkshimAsyncLink.swap(this, &amp;quot;http:\\\\\\/\\\\\\/stackoverflow.com\\\\\\/questions\\\\\\/16385364\\\\\\/when-an-activity-binds-an-already-binded-service-the-onrebind-gets-the-old-inten&amp;quot;);\\&quot; onclick=\\&quot;LinkshimAsyncLink.referrer_log(this, &amp;quot;http:\\\\\\/\\\\\\/stackoverflow.com\\\\\\/questions\\\\\\/16385364\\\\\\/when-an-activity-binds-an-already-binded-service-the-onrebind-gets-the-old-inten&amp;quot;, &amp;quot;http:\\\\\\/\\\\\\/www.facebook.com\\\\\\/si\\\\\\/ajax\\\\\\/l\\\\\\/render_linkshim_log\\\\\\/?u=http\\\\u00253A\\\\u00252F\\\\u00252Fstackoverflow.com\\\\u00252Fquestions\\\\u00252F16385364\\\\u00252Fwhen-an-activity-binds-an-already-binded-service-the-onrebind-gets-the-old-inten&amp;amp;h=XAQE9ndNZ&amp;amp;s=1&amp;quot;);\\&quot;&gt;preview\\u003C\\/a&gt;.\\u003C\\/div&gt;&quot;)).setWidth(300).setContext(this).enableBehavior(LayerHideOnBlur).disableBehavior(LayerDestroyOnHide).show();\"><div id=\"id_518a13acd3ae61862974322\" class=\"text_exposed_root\">When an activity binds an already binded service<span class=\"text_exposed_hide\">...</span><span class=\"text_exposed_show\"> the onRebind gets the old intent? - Stack Overflow</span><span class=\"text_exposed_hide\"><span class=\"text_exposed_link\"><a onclick=\"CSS.addClass($(&quot;id_518a13acd3ae61862974322&quot;), &quot;text_exposed&quot;); Arbiter.inform(&quot;reflow&quot;);\" data-ft=\"&#123;&quot;tn&quot;:&quot;e&quot;&#125;\">See More</a></span></span></div></a></div></div><div class=\"mts fsm fwn fcg\"><div class=\"whitespaceLink\" id=\"u_0_4\"><a class=\"_24x\" onclick=\"new LegacyContextualDialog().init(HTML(&quot;\\u003Cdiv class=\\&quot;pam\\&quot;&gt;\\u003Cdiv class=\\&quot;mbs fwb\\&quot;&gt;Linkable Area\\u003C\\/div&gt;The comment and like icons click through to a page with the original story. \\u003Ca target=\\&quot;_blank\\&quot; href=\\&quot;\\/AndroidDevelopersDiscussion\\/posts\\/533162160059295\\&quot;&gt;preview\\u003C\\/a&gt;\\u003C\\/div&gt;&quot;)).setWidth(300).setContext(this).enableBehavior(LayerHideOnBlur).disableBehavior(LayerDestroyOnHide).show();\" id=\"u_0_5\"></a><a class=\"uiBlingBox\" href=\"\" data-ft=\"&#123;&quot;tn&quot;:&quot;O&quot;&#125;\" rel=\"async\" ajaxify=\"/ajax/permalink/overlay.php?story_fbid=533162160059295&amp;id=100000965480505&amp;disableego=1&amp;eid=AQL9b9q1T3-bndMGNfqwl7ueBMWsDM7ToQguvrFfxI0vbRYSFFhHDoAMMaZJ2_WaEpqH1KGMmseEc-_c5sFzvSJ5KS_cMvEYArjt6PMKFERuoPUR1PydRr6hSL63YL33saf1AFQUgHqWs7lydjLQyg74SqWPG52EJatOEKbT2uApx8qZnJYFagfLR0vdx9Jezl7yAcMe-PCPr0NmIvt9q9L_0nhjD67DBArKiSm0ZMMS9uuEMjtztsn4_AWIh1pWARDA8mAZJSyL_Nc3kEpF_CTnUiVVcMSp1genwxQbK5J4yvnoyGMeFiYdiZvumJPeyV4238K8Xgwed3Ts3Z2BAlQlrGLKGTjTOaNI52zHxEJi9TyqJQRKoh6yvjnMxWo9kmKo5ylTbC1anDCQL-in8GB-4WRRgq7kUdcRl1Nbz_HVTfUE1nAufOq3d-e_ajX1gwzBOnUlJOcHseuvQz4-KhbcwlOAPo7xgnm77C-oxFu7Q9AKaP0Ca_N2fgmfalGcJtZIWInrOg_OJq72_9m9dSh1uWpdCTiI6aF9KAPjNzJPTOnI-oEZB4P9W2pDRO7coRx80JZti6BtwAcWTOUb1v_X700PmgIc3I10Z2arAoWFakFocxMzHjekyDjaUXVnmmmtZX8NLI7_IR1UWgQXoMi98ijj662eav7g6J1wC95BxDB3GImGQSEDjWkVbMMwI6mvwGAbTwscjSQTkOSsH07VjUvKvEvHJIqSOC2YQDl_xrHqiHcwY0pODekoVFjWB-4VBNQNKVRsxN1kJ1m_bYid9zSroMG3dED7JrhvhWpUPAVfDum9r4XE7HZw6Y16t-26pdLtIvIxcPxEbe0-bRbmhMpyLIR2vUhTG1jhMW_whFfWth5Qg3rwltQl4KEfEcCty_2mq3BMkmk6h_3JUBgQr90u54TDc0tQfR6-W3vr0FsO7RnMAUICFKrfKLr7ucrgltipaiIuk203BiafJOLNaWshte3knvLgRkgZxo42gX6n972nw-TuugfxfwvbTfOSGZQqXOJi2liFhPzkQzFBShfh0v9Lkm09rrSdK8MUGee6d-nLxYKq3Dvmc4p97Lxn9z5--jjDM2NdsM_65-L8-xhH_dL_Gp9zsIvHzsxni442L6-6_XrqJ3os0v8VYIo6jtxHyHBN1Ph07loGfG58x2OLI2BSu-1WE1XauL9XWunQWVhab3hTWKuJjgIJOYY3CcBBQmvwJyuZYKRetMYUD9upcujOOwXH7rQSVC-GKpSHmjuRVCDqtwINJ8OgGVq3CQI6d4t0zxSRt58LdB2K-BmitZMLOYDilGWqSBKvMhW2To507uIrRAD34Bz6nklie4lnAVQeK_mip0yC_RLkR6sxC2cTmi_Zs6V3jxiPL2IvZIhBU406EdMPGsLguNlulScHxgCS7YF1ALAizgwst73jJqnR7v1yx9NABYydaAqEc-VqS3chgZAaw-mEdeJf5jCDzEGaUvV5fCjC-V8-tp7MKiwSPdYykF_bjqmoBElXnNIayaANCCQtGdgxOgjbflXjh22vjqTQKfRndETmmwXtC_oVc9gMlpGTJFnS-bp-plDryuwRXwtakV3OHmQBkveGasTexB6mHnjS5cSwLDZDBXAdnDcT6K55jLI54A&amp;en=fad_strfooteroverlayclick\">Like · Comment</a></div> · <a class=\"_24x\" href=\"#\" onclick=\"new LegacyContextualDialog().init(HTML(&quot;\\u003Cdiv class=\\&quot;pam\\&quot;&gt;\\u003Cdiv class=\\&quot;mbs fwb\\&quot;&gt;Linkable Area\\u003C\\/div&gt;Users who click this area will see a internal dialog window overlay the current page. \\u003Ca href=\\&quot;\\/ajax\\/sharer?s=99&amp;amp;appid=2309869772&amp;amp;p\\u00255B0\\u00255D=100000965480505&amp;amp;p\\u00255B1\\u00255D=533162160059295\\&quot; rel=\\&quot;dialog\\&quot; data-ft=\\&quot;&amp;#123;&amp;quot;tn&amp;quot;:&amp;quot;J&amp;quot;,&amp;quot;type&amp;quot;:25&amp;#125;\\&quot; title=\\&quot;Send this to friends or post it on your timeline.\\&quot; role=\\&quot;button\\&quot;&gt;Share\\u003C\\/a&gt;.\\u003C\\/div&gt;&quot;)).setWidth(300).setContext(this).enableBehavior(LayerHideOnBlur).disableBehavior(LayerDestroyOnHide).show();\" data-ft=\"&#123;&quot;tn&quot;:&quot;J&quot;,&quot;type&quot;:25&#125;\" title=\"Send this to friends or post it on your timeline.\" role=\"button\">Share</a></div></div></div></div></div></div></div><div class=\"unclickableMask\"></div></div>"
    }
  ]
}

我还使用此请求下载了正确的 css:

https://graph.facebook.com/act_MY_ACT_ID/adpreviewscss?accesstoken=MY_ACCESS_TOKEN

并得到:
{我不能把 css 放在这里,因为它很长,但你可以在这里看到它}

但无论我做什么,HTML 看起来都不好。它坏了。
我试过html_entity_decodeand htmlspecialchars_decode,但没有用。(我在服务器端使用 PHP)
您知道如何使代码段成为有效的 HTML 吗?

4

1 回答 1

0

找到了。使用 `stripslashes' 删除不需要的 '/' 。

于 2013-05-08T11:32:30.753 回答