0

I have a share functionality on my site, the meta data is built dynamically from the model the problem I have the user can make a combination of ingredients and then click share with friends, clicking this button takes them to a thank you page where the combination they have created is displayed, and the meta data is created by appending the image name and the image title using

@Model.ImageCombintation
@Model.ImageTitle

My controller looks like this

 public ActionResult ThankYou()
    {
        var model = (LabCombination)Session["Comb"];

        return View(model)
    }

Inside LabCombination consists of the image, title and other additional information.

I built the meta data like this appending the @Model details to the end and it gets rendered as follows:

 <meta property="og:title" content="Check out the flavour I just made! Blackcherry &amp; Cinnamon" />
 <meta property="og:description" content="Check out the flavour I have just created!" />
 <meta property="og:image" content="http://danone.staging-eurorscg.com.au/Content/Images/FlavourLab/CombinationSmall/danone_ultimate_blackcherry_cinnamon.png" />
 <meta property="og:url" content="http://danone.staging-eurorscg.com.au/thank-you" />

This works fine for the first time round, but when I go back to the page and create another combination and click share with friends the meta data is updated yet the share dialog shows the previous combination as shown here for an example, the image you see in the middle is the new combination where as the image in the share dialog pop up is the previous image.

enter image description here

Now I have googled this and many people have suggested using https://developers.facebook.com/tools/debug/og/object/ and scrapping the page again, that's fine but its pointless when this site is live as many people are creating different combinations I need the affect to be instant not sit around waiting for it to reflect new images! and nor will I be scrapping the page again.... how can I get around this?

Update

After reading whats on the intenet alot of people are saying if you need to update the content on the share functionality then you need to resubmit the object with the 'scrape' parameter set to 'true' in your POST request. Below is what I have on the bottom of my page

<script>
    $(document).ready(function () {
        (function (d, s, id) {
            var js, fjs = d.getElementsByTagName(s)[0];
            if (d.getElementById(id)) return;
            js = d.createElement(s);
            js.id = id;
            js.src = "//connect.facebook.net/en_GB/sdk.js#xfbml=1&version=v2.0";
            fjs.parentNode.insertBefore(js, fjs);
        }(document, 'script', 'facebook-jssdk'));
    });
</script>

Where would I put that?

** Another Update **

I have the found the following off this thread Facebook Open Graph not clearing cache

            (function (d, s, id) {
        var js, fjs = d.getElementsByTagName(s)[0];
        if (d.getElementById(id)) return;
        js = d.createElement(s);
        js.id = id;
        js.src = "//connect.facebook.net/en_GB/sdk.js#xfbml=1&version=v2.0";
        js.scrape = true;
        fjs.parentNode.insertBefore(js, fjs);
    }(document, 'script', 'facebook-jssdk'));

    window.fbAsyncInit = function () {
        //FB.init({
        //    appId: '1621733871379311',
        //    xfbml: true,
        //    version: 'v2.2'
        //});

        //FB.clear_cache("http://danone.staging-eurorscg.com.au/thank-you");
    };

    $.post('https://graph.facebook.com', {
        id: 'http://danone.staging-eurorscg.com.au/thank-you',
        scrape: true
    },
function (response) {
    console.log(response);
}
);

I've tried this but surprise surprise it doesn't work. All I want to do is clear the cache why is the documentation so limited on this?

Community
  • 1
  • 1
Code Ratchet
  • 5,758
  • 18
  • 77
  • 141
  • Why are you creating a new post every hour? Create unique urls and share them. If you change the title everyone that already have shared it will also change – WizKid Feb 26 '15 at 01:25
  • @WizKid because everyone will create a different combination but saying that I'm having the one main default title now which reads "Check out the flavour I just made!" but this still doesn't fix the the issue, how can I clear the meta data so the new image is shown instead of having the previous one – Code Ratchet Feb 26 '15 at 01:29
  • Use the debugger and rescrape. But even better is that you just create a unique url for each flavour. Then you share that url and that url will have the right og-tags – WizKid Feb 26 '15 at 02:01
  • @WizKid I've just rescraped it, So I have 16 combinations with 16 unique URLS which look like this http://danone.staging-eurorscg.com.au/Content/Images/FlavourLab/CombinationSmall/image2.png" http://danone.staging-eurorscg.com.au/Content/Images/FlavourLab/CombinationSmall/image1.png" http://danone.staging-eurorscg.com.au/Content/Images/FlavourLab/CombinationSmall/image3.png" etc I'm not sure how this is going to work because I need to clear the cache! the Meta data already changes the way I'm currently doing it, I need to clear the cache as facebook caches the page for 24 hours – Code Ratchet Feb 26 '15 at 02:05
  • @WizKid also where would I put these 16 urls? – Code Ratchet Feb 26 '15 at 02:08
  • Just use the debugger and click Fetch new data – WizKid Feb 26 '15 at 04:08
  • @WizKid I'm fully aware of the debugger and what it does when the site is live I need to clear the cache so it refreshes the image in share dialog as it currently sticks to showing he first image this is due to the fact facebook scraps the page and refers to the cache for 24 hours. so If person 1 came on to the site and created a combination and then shared it, person 2 came along and made a combination person 2 would see person 1's image in the shared dialog, you mentioned about creating a unique URL for each combination unfortunately adding 16 pages for each combination is not acceptable. – Code Ratchet Feb 26 '15 at 04:25
  • Create them dynamically. Of course you can not create an html file for each. But you can have page.php?id=1 or flavor=foo and then change the og-tags depending on them – WizKid Feb 26 '15 at 04:48
  • You must understand if you share example.com/foo and then later change the og-tags everyone that shared that url will have the data updated. So keep unique data per url – WizKid Feb 26 '15 at 04:49
  • @WizKid I understand, well I wont be implementing 16 unique pages for the sake of using the share functionality. – Code Ratchet Feb 26 '15 at 04:57
  • Then you need to make all shares the same – WizKid Feb 26 '15 at 05:29
  • I'll speak to guys could be worth having one generic image – Code Ratchet Feb 26 '15 at 05:36
  • Yea because having unique images are probably a 5-10 minutes job – WizKid Feb 26 '15 at 05:37

0 Answers0