5

I am trying to share an image from my website on facebook. The image can be dynamic, but other meta will remain the same.

Is there a way I can have dynamic data in OG:IMAGE tag, or will I have to go with the other option of FB Post APIs.

2 Answers 2

9

Yes and no. Facebook scrapes your site once, and cached the metadata that it finds, unless you specifically go here and force the scraper to crawl your site again. The cache does generally expire (perhaps after 1-2 days?), so when requested again outside of this cache period, Facebook will crawl the site again.

You can have a dynamically generated og:image meta tag, but it will only be read the one time (per cache period), and only that instance of the image will be saved.

For example, if user A shares your page, and your page returns imageA.png in the og:image tag, then that is the image that will be associated with your page's metadata.

If user B then shares the same page within the same cache period, Facebook will forgo the metadata scraping and assume that imageA.png is still a valid og:image.

1
  • 1
    One option to make the dynamic og:image dynamic show on Facebook is to add a cachebuster to the og:image src. Therefore with every page rescraping from Facebook (every 24 hours) it will see a new image.
    – j0nes
    Apr 7, 2014 at 16:55
0

Take a look at this Gist.

You should ping facebook to recrawl your page again every time you update your og:image tag.

def share_facebook_fanpage(link,msg,PAGE_ID,OAUTH_ACCESS_TOKEN,apiversion='v2.8'):
    BASE_URL = "https://graph.facebook.com/%s" % apiversion
    POST_URL = "%s/%s/feed" % (BASE_URL, PAGE_ID)

    # force facebook scape the link first to avoid not showing thumb
    f = requests.post(BASE_URL, data={
        'id': link,
        'scrape': True,
        'access_token': OAUTH_ACCESS_TOKEN
    })

    # share the link
    r = requests.post(POST_URL, data={'access_token': OAUTH_ACCESS_TOKEN, 'link': link, 'message':msg})
0

Not the answer you're looking for? Browse other questions tagged or ask your own question.