简体   繁体   中英

How can i get wall post same as facebook using php

maybe it not the correct question but i'm looking for help, i have use curl, DOMDocument, and file_get_contents to get a image tag as facebook do but i can't. 在此处输入图片说明

some thing like this.

Facebook uses specific Open Graph meta tags that publishers can use to suggest an image, title, and description for Facebook to use when sharing a URL. You will want to load the HTML with DOMDocument, and then look for these tags.

Look for tags with og: in the name, like this:

<meta property="og:image" content="http://example.com/image.png" />

See also: http://davidwalsh.name/facebook-meta-tags

My code look like this: i'm trying to get image image from yahoo link just like test https://es.finance.yahoo.com/noticias/amazon-prev-vender-un-smartphone-200856947.html

header('Content-Type: application/json');
if(isset($_GET['c_txt'])){
$url = $_GET['c_txt'];
if(curl_init($url)){
    $html = file_get_contents($url);

    $doc = new DOMDocument();
    @$doc->loadHTML($html);

    $tags = $doc->getElementsByTagName('img');

    foreach ($tags as $tag) {
           echo $tag->getAttribute('src') . "\n";
    }
  }
}

but the result looks like:

https://sb.scorecardresearch.com/b?  c1=2&c2=7241469&c7=es.finance.yahoo.com%2Fnoticias%2Famazon-prev-vender-un-smartphone-200856947.html&c5=1185584786&c15=$&cv=2.0&cj=1
https://s.yimg.com/dh/ap/default/130307/expansion_header_article.png
https://s.yimg.com/os/mit/media/m/base/images/transparent-1093278.png
https://s.yimg.com/os/mit/media/m/base/images/transparent-1093278.png
https://s.yimg.com/os/mit/media/m/base/images/transparent-1093278.png
https://s.yimg.com/os/mit/media/m/base/images/transparent-1093278.png
https://s.yimg.com/os/mit/media/m/base/images/transparent-1093278.png
https://s.yimg.com/os/mit/media/m/base/images/transparent-1093278.png
https://s.yimg.com/os/mit/media/m/base/images/transparent-1093278.png
https://s.yimg.com/dh/ap/default/130711/masnoticiasen2.jpg
https://s.yimg.com/os/mit/media/m/base/images/transparent-1093278.png
https://s.yimg.com/os/mit/media/m/base/images/transparent-1093278.png

and not the image that display at facebook, the tag what i want is this one: 在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM