Reado
Reado

Reputation: 1452

Posting via Facebook API but image does not appear

I am using the Facebook PHP SDK to post content to our company page. 9 times out of 10, it works, but on the odd occasion like today the post is submitted and its content appears on the page but without the image provided by the og:image meta tag.

In today's case, a URL was submitted but no image is being displayed. According to Facebook's Sharing Debugger, there is a warning stating the "provided og:image URL encountered an unexpected error", despite the server access logs showing a request made to that image URL by the Facebook crawler at around the time the URL was submitted and a code 200 being returned along with 1MB+ of data.

The Object Debugger says different. It claims the web server is not running or Facebook's crawlers are being blocked, which according to the firewall logs is not the case. There are also warnings stating the og:url and fb:app_id tags are missing even though they appear in the raw output.

Scraping the URL again does not pull the image through; I have to manually use the "refresh share attachment" feature to make the image appear.

Is there any way I can rescape a URL and refresh the share attachment using PHP without having to do it manually?

Upvotes: 2

Views: 856

Answers (1)

misorude
misorude

Reputation: 3431

Scraping the URL again does not pull the image through; I have to manually use the "refresh share attachment" feature to make the image appear.

Of course it doesn’t, otherwise I would change the kitten picture of that article of mine you posted three days ago, to “buy cheap viagra here” today, and you would automatically have that reflected on your timeline …

Is there any way I can rescape a URL and refresh the share attachment using PHP without having to do it manually?

You can (re-)scrape URLs via API – https://developers.facebook.com/docs/sharing/opengraph/using-objects#update

But I am not sure whether updating a post with the exact same values would actually count as an update, and refresh the attachment. You can give it a try (https://developers.facebook.com/docs/graph-api/reference/v3.1/post#updating), but if it doesn’t work, then your only option is to make sure everything is working properly before you make the post. (The JSON data returned from that endpoint should contain the image URL if everything worked properly, I suppose.)

Upvotes: 1

Related Questions