gpt4 book ai didi

node.js - LinkedIn URL 预览在共享时不起作用

转载 作者:行者123 更新时间:2023-12-04 09:34:41 25 4
gpt4 key购买 nike

我创建了一个简单的 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 网络爬虫的问题。

最佳答案

我相信 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>

关于node.js - LinkedIn URL 预览在共享时不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62648291/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com