I had the same problem, I wanted to share the user's score in the quote section of the facebook sharing link. Unfortunately, in 2017 Meta deprecated the ability to edit previews attached to link posts: here's the article
However, I found a workaround, although is not very pretty. I'm using Next.JS with next-share in my project, but you can probably achieve the same with other frameworks:
I created a dynamic route with the data I wanted to share as a parameter, and used it to make the content string for the meta tag og:description. I then used the url of the dynamic route for the share button, this way the facebook crawler is reading the dynamic description. You can't use redirection though, I had to make some sort of landing page with a button that redirects the user to the desired page. Here's the code:
dummy page:
// /app/[phrase]/page.jsx
import FacebookLandingPage from '../../components/FacebookLandingPage.jsx'
export default function Phrase({ params }) {
const gameData = params.phrase.split("%2C");
const difficulty = gameData[1] == "Easy" || gameData[1] == "Medium" || gameData[1] == "Hard" || gameData[1] == "Expert" ? gameData[1] : "";
let minutes;
let seconds;
let attempts;
if (gameData[0] == "crack-the-code"
&& parseInt(gameData[2])
&& parseInt(gameData[2]) < 10) {
attempts = gameData[2]
} else if (gameData[0] == "sudoku"
&& parseInt(gameData[2])
&& parseInt(gameData[3])) {
minutes = gameData[2]
seconds = gameData[3];
}
const img = params.phrase.match("sudoku") ? "sudoku" : params.phrase.match("crack-the-code") ? "crack-the-code" : "";
const sudokuPhrase = `I completed a${difficulty == "Easy" || difficulty == "Expert" ? "n" : ""} ${difficulty} Sudoku in ${minutes} minute${minutes != 1 ? "s" : ""} and ${seconds} second${seconds != 1 ? "s" : ""}! Can you do better?`;
const ctcPhrase = `I cracked a${difficulty == "Easy" || difficulty == "Expert" ? "n" : ""} ${difficulty} code in ${difficulty == "Easy" ? 7 - attempts : difficulty == "Medium" ? 8 - attempts : difficulty == "Hard" ? 9 - attempts : 10 - attempts} attempts! Can you do better?`;
const sharePhrase = gameData[0] == "crack-the-code" ? ctcPhrase : gameData[0] == "sudoku" ? sudokuPhrase : "";
return (
<>
<meta
property='og:image'
content={`https://puzzle-challenge.vercel.app/images/${img}.png`}
/>
<meta
property='og:description'
content={sharePhrase}
/>
<FacebookLandingPage/>
</>
)
}
then, in the game page:
<FacebookShareButton
url={`https://puzzle-challenge.vercel.app/sudoku,${difficulty},${minutes},${seconds}`}
hashtag={'#sudoku'}
>
<FacebookIcon size={32} round className='my-1'/>
</FacebookShareButton>