Facebook scraper not validating og:image url

折月煮酒 提交于 2020-01-06 02:36:09

问题


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.

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'.

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..

<meta property="og:image" content="&lt;img src='http://www.mypage.org/images/post_images/4121.jpg' /&gt;">

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.


回答1:


You shouldn't embed the HTML tag into the content of the meta tag. Try this format instead:

<meta property="og:image" content="http://www.mypage.org/images/post_images/4121.jpg">



回答2:


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:

<meta property="og:image" content="http://www.mypage.org/images/post_images/4121.jpg">


来源:https://stackoverflow.com/questions/8606272/facebook-scraper-not-validating-ogimage-url

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!