1 回答

TA貢獻1893條經驗 獲得超10個贊
我找到了解決方案。發布此答案以幫助正在尋找類似解決方案的任何人。
https://www.opengraph.io/每月免費提供多達 100 個請求。您需要注冊以獲取要放入 app_id 的 API 密鑰。只需幾行代碼,我就可以在響應對象中獲取元數據:
getOpenGraph(url) {
const encodedURL = encodeURIComponent(url)
axios
.get(`https://opengraph.io/api/1.1/site/${encodedURL}?app_id=xxxxxxx`)
.then(res => { console.log(res.data.hybridGraph) })
.catch(err => { console.log(err) })
}
此頁面的打開圖形數據如下:
{
description: "When an user submit a post with an URL. I want to get the Open Graph meta of the URL without a back-end server. I've found libraries that can extract Open Graph meta such as opengraph-io and metasc...",
favicon: 'https://cdn.sstatic.net/Sites/stackoverflow/Img/favicon.ico?v=ec617d715196',
image: 'https://cdn.sstatic.net/Sites/stackoverflow/Img/[email protected]?v=73d79a89bded',
site_name: 'Stack Overflow',
title: 'How to get Open Graph meta from URL input on the client side',
type: 'website',
url: 'https://stackoverflow.com/questions/62634812/how-to-get-open-graph-meta-from-url-input-on-the-client-side'
}
添加回答
舉報