Seb
Seb

Reputation: 116

Link preview not showing when posting to Facebook page via Graph API

When posting a link to Facebook page the link preview image does not show up.

I checked whether I have the correct OG tags and they're there. After posting, If I edit the post manually and add a space after the link, the preview loads as expected.

Is there a specific way to post the message and link as string so the preview loads up?

The below is a snippet of how the message is posted:

var postMessage = string.Format($"{content.Url} ");

var postData = new Dictionary<string, string>
{
   {"access_token", apiKeys.PageAccessToken},
   {"message", postMessage}
};

var result = httpClient.PostAsync($"https://graph.facebook.com/{pageId}/feed", new FormUrlEncodedContent(postData)).Result;

Thanks

Upvotes: 2

Views: 575

Answers (1)

Seb
Seb

Reputation: 116

The solution given in a comment by 04FS has fixed the issue.

All I had to do was replace message with link as shown below:

var postData = new Dictionary<string, string>
{
    {"access_token", apiKeys.PageAccessToken},
    {"link", postMessage}
};

This way the Graph API picks it up and link preview shows immediately after posting.

Upvotes: 1

Related Questions