【问题标题】:How can i get wall post same as facebook using php如何使用 php 获得与 facebook 相同的墙帖
【发布时间】:2014-04-19 03:57:38
【问题描述】:

也许这不是正确的问题,但我正在寻求帮助,我已经使用 curl、DOMDocument 和 file_get_contents 来获取图像标签,就像 facebook 一样,但我不能。

类似的东西。

【问题讨论】:

    标签: php facebook curl domdocument file-get-contents


    【解决方案1】:

    Facebook 使用特定的 Open Graph 元标记,发布者可以使用这些标记来建议 Facebook 在共享 URL 时使用的图像、标题和描述。您需要使用 DOMDocument 加载 HTML,然后查找这些标签。

    查找名称中带有og: 的标签,如下所示:

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

    另请参阅:http://davidwalsh.name/facebook-meta-tags

    【讨论】:

    • 感谢您回答我的问题,但我的意思是在我的页面上执行我所说的操作。我试图像一个测试一样,来自雅虎的相同链接,但我得到的只是空图像。你有什么想法吗?
    • @manout 我刚刚告诉你如何获取该图像的 URL。如果您的特定代码无法正常运行,您应该针对该代码提出特定问题。
    【解决方案2】:

    我的代码如下所示: 我正在尝试从雅虎链接获取图像图像,就像测试一样 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";
        }
      }
    }
    

    但结果看起来像:

    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
    

    而不是在 facebook 上显示的图像,我想要的标签是这个:

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-24
    • 1970-01-01
    相关资源
    最近更新 更多