【问题标题】:LinkedIn URL preview not working while sharingLinkedIn URL 预览在共享时不起作用
【发布时间】:2020-10-20 05:11:32
【问题描述】:

我创建了一个简单的 Node.js Web 服务器来在浏览器上呈现 html 内容。具体来说,该 html 包含用于在社交媒体上共享的元标记,以便在网站链接在 FB、Twitter、LinkedIn 等社交平台上共享后立即启用 URL 预览。

我已经在返回的 html 内容中添加了用于共享的开放图形标签。它适用于 FB 和 Twitter,但会出现“我们在尝试检查 URL 时遇到服务器错误”的错误。作为回应。

这是带有虚拟端点的服务器代码。

const express=require('express');
const app = express();

require('dotenv').config();

app.get('/dummy',(req,res)=>{
    res.send(`
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Dummy Endpoint</title>
        <meta name="type" content="article" />
        <meta name="title" content="Dummy Endpoint"/>
        <meta name="description" content="Used for testing"/>
        <meta name="image" content="https://www.kindpng.com/picc/m/252-2524695_dummy-profile-image-jpg-hd-png-download.png"/>
        <meta property="og:type" content="article"/>
        <meta property="og:title" content="Dummy endpoint"/>
        <meta property="og:description" content="Used for testing"/>
        <meta property="og:image" content="https://www.kindpng.com/picc/m/252-2524695_dummy-profile-image-jpg-hd-png-download.png"/>
        <meta property="og:image:secure_url" content="https://www.kindpng.com/picc/m/252-2524695_dummy-profile-image-jpg-hd-png-download.png"/>
        <meta property="og:image:secure" content="https://www.kindpng.com/picc/m/252-2524695_dummy-profile-image-jpg-hd-png-download.png"/>
        <meta property="og:image:width" content="600" />
        <meta property="og:image:height" content="450" />
        <meta name="twitter:title" content="Dummy Endpoint"/>
        <meta name="twitter:description" content="Dummy endpoint"/>
        <meta name="twitter:image" content="https://www.kindpng.com/picc/m/252-2524695_dummy-profile-image-jpg-hd-png-download.png"/>
        <meta name="twitter:card" content="summary"/>
    `)
})

app.listen(process.env.PORT || 5000, () => {
    console.log('Server started at '+process.env.PORT)
});


网站链接:https://whispering-woodland-66525.herokuapp.com/dummy(页面为空,在 Inspect 中检查 head 部分)

Facebook 分享调试器回复:https://developers.facebook.com/tools/debug/?q=http%3A%2F%2Fwhispering-woodland-66525.herokuapp.com%2Fdummy

LinkedIn Post Inspector 回复:https://www.linkedin.com/post-inspector/inspect/https:%2F%2Fwhispering-woodland-66525.herokuapp.com%2Fdummy

我已尝试多次刷新 Post Inspector 页面,并在 Post Inspector 中的 url 中添加一个虚拟查询参数,以防止提供缓存的内容,但没有成功。

我无法理解代码中是否存在错误或缺失,或者是否是 LinkedIn 网络爬虫的问题。

【问题讨论】:

    标签: node.js linkedin


    【解决方案1】:

    我相信 LinkedIn Post Inspector 期待一个完整的 HTML 文档。考虑将元数据包装到文档的标题中。尝试返回:

    <!DOCTYPE html>
      <html lang="en">
        <head>
           <meta charset="UTF-8">
           <meta name="viewport" content="width=device-width, initial-scale=1.0">
           <title>Dummy Endpoint</title>
           <meta name="type" content="article" />
           <meta name="title" content="Dummy Endpoint"/>
           <meta name="description" content="Used for testing"/>
           <meta name="image" content="https://www.kindpng.com/picc/m/252-2524695_dummy-profile-image-jpg-hd-png-download.png"/>
           <meta property="og:type" content="article"/>
           <meta property="og:title" content="Dummy endpoint"/>
           <meta property="og:description" content="Used for testing"/>
           <meta property="og:image" content="https://www.kindpng.com/picc/m/252-2524695_dummy-profile-image-jpg-hd-png-download.png"/>
           <meta property="og:image:secure_url" content="https://www.kindpng.com/picc/m/252-2524695_dummy-profile-image-jpg-hd-png-download.png"/>
           <meta property="og:image:secure" content="https://www.kindpng.com/picc/m/252-2524695_dummy-profile-image-jpg-hd-png-download.png"/>
           <meta property="og:image:width" content="600" />
           <meta property="og:image:height" content="450" />
           <meta name="twitter:title" content="Dummy Endpoint"/>
           <meta name="twitter:description" content="Dummy endpoint"/>
           <meta name="twitter:image" content="https://www.kindpng.com/picc/m/252-2524695_dummy-profile-image-jpg-hd-png-download.png"/>
           <meta name="twitter:card" content="summary"/>
       </head>
    </html>
    

    【讨论】:

    • 这是一个很好的收获@TuanGeek。它工作得很好。谢谢。
    猜你喜欢
    • 2015-11-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-13
    相关资源
    最近更新 更多