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

标签 node.js linkedin-api

我创建了一个简单的 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 岗位检查员的回复: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/

相关文章:

javascript - 从函数-Node JS -socket.io发出事件的正确方法

javascript - 无法从 React 前端向 Node.js 后端发送 POST 请求

node.js - NG Live Development Server 与传统 Web 服务器

android - 下载官方安卓 LinkedIn APK

linkedin - 如何在向 Linkedin 上的配置文件添加证书时自动填充字段

node.js - Discord.js - guildMemberUpdate 不会被调用,除非机器人用户发生更改

node.js - 适用于 Azure 的 iisnode 的 if(require.main) 模式

linkedin-api - 领英 v2 API : How can a ugcPost-URN be converted to a share URN?

android - 未通过调用 LinkedIn API Oauth 2.0 版获取公开个人资料 URL

javascript - 如果有人在 linkedin 上发帖,如何获得通知。 linkedIn是否提供任何webhook API