php Facebook 抓取工具未验证 og:image url
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8606272/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Facebook scraper not validating og:image url
提问by wowzuzz
I am running some functions on my controller to come up with a custom meta tag url that is then taken and used on the opengraph image tag for facebook. This image gets put in a variable, that then gets displayed on a url used for scraping on facebook. I got it working the right way and now the linter comes back at me with this error.
我正在我的控制器上运行一些函数来提出一个自定义元标记 url,然后将其用于 facebook 的 opengraph 图像标记。该图像被放入一个变量中,然后显示在用于在 facebook 上抓取的 url 上。我让它以正确的方式工作,现在 linter 以这个错误返回给我。
Object at URL 'http://mypage.org/pages/post.html?PostID=9192&prog=' of type 'website' is invalid because the given value '' for property 'og:image:url' could not be parsed as type 'url'.
位于 URL 'http://mypage.org/pages/post.html?PostID=9192&prog=' 类型为 'website' 的对象无效,因为无法将属性 'og:image:url' 的给定值 '' 解析为输入“网址”。
How is that not a valid url? I can take the link and put it in my browser and it comes up just fine. I notice as well when I go down to see the scraped url it gives me back this..
这怎么不是一个有效的网址?我可以获取链接并将其放入我的浏览器中,它出现得很好。我也注意到,当我下去看到抓取的 url 时,它给了我这个..
<meta property="og:image" content="<img src='http://www.mypage.org/images/post_images/4121.jpg' />">
Looks like it takes my < and />, makes them into hex..why would the scraper do this? Btw here is the code from my controller.
看起来它需要我的 < 和 />,使它们变成十六进制......为什么刮板会这样做?顺便说一句,这是来自我的控制器的代码。
$img = strstr($img, '<img src=');
$substring = substr($img, 0, strpos($img, "/>"));
$img = $substring . "/>";
What this code does is I take the code before the to the end of the url making a full <img src = "" />
url. Any and all help is very much appreciated.
这段代码的作用是我在 url 的末尾获取代码,从而生成完整的<img src = "" />
url。非常感谢任何和所有帮助。
回答by DMCS
You shouldn't embed the HTML tag into the content of the meta tag. Try this format instead:
您不应将 HTML 标记嵌入到元标记的内容中。试试这个格式:
<meta property="og:image" content="http://www.mypage.org/images/post_images/4121.jpg">
回答by Jo?o Teixeira
The content of your meta property should be the URL for the image, not a DOM element. Replace your og:image meta property by this one and it should work:
元属性的内容应该是图像的 URL,而不是 DOM 元素。用这个替换你的 og:image 元属性,它应该可以工作:
<meta property="og:image" content="http://www.mypage.org/images/post_images/4121.jpg">