0

I'm trying Facebook open graph, and I want to assign og:description dynamically when a user share my page, and it's determined by my php.

<meta name="og:title" content="test1" />  
<meta name="og:description" content="<?php  echo $_REQUEST['parm'] ?>" />  
<meta name="og:image" content="http://nuphoto.com.tw/titleapp4.png" />  
<meta name="og:url" content="http://nuphoto.com.tw/share/easygo_bruce.php" />  

However, it always caches the previous result, and it doesn't change. I googled the solution , but all of them didn't work. Here're my trials.

  • Go to https://developers.facebook.com/tools/debug and enter my url. it works, but I need to change my page dynamically. so it's not suitable for me.

  • Follow How to update facebook open graph image

    $.post(
    'https://graph.facebook.com',
    {
        id: 'http://www.example.com/my/share/url/',
    scrape: true
    },
    function(response){
    console.log(response);
     });
    

    it didn't work, and showed error.

    FB.getLoginStatus() called before calling FB.init(). all.js:53
    Object {url: "http://example.com/mytest.php", type: "website", title: "test, image: Array[1], description: "XXX"…}
    
    • Someone said add v=XXX&fbrefresh=XXX may help, but it still fails for me.

    https://www.facebook.com/sharer/sharer.php?u=example.com&fbrefresh&v=xxxx

Please help me , I already spent hours of work....

Community
  • 1
  • 1
Bruce Tsai
  • 1,440
  • 2
  • 12
  • 18

3 Answers3

0

None of those solutions will work for you, Why?

Facebook debugger scrapes your URL and get the static HTML (meta) of your pages. Facebook BOT is not a user with a session!, it scrapes your page meta tags, refresh its cache and get out that's all

<meta name="og:description" content="<?php  echo $_REQUEST['parm']; ?>" />

$_REQUEST['parm'] is what the current user/session see and set, while the debugger doesn't have a session or $_REQUEST['parm'] set.

sincerely, you can't change og:image dynamically according to the current session.

Adam Azad
  • 11,171
  • 5
  • 29
  • 70
0

In fact , what I want is to make a dynamically FB description, I will show different coupon code for each FB sharing post. So I need to pass the coupon code to description. I can't find the correct way. Using get string in sharer.php?u=http://example.com.tw?coupon=DXSCVV didn't work.

Finally, I use php to generate a file dynamically, which this file has the file name of coupon, such as DXSCVV.htm. sharer.php ->sharer.php?u=http://example.com.tw/DXSCVV.htm

It works. Thank you for your help.

Bruce Tsai
  • 1,440
  • 2
  • 12
  • 18
0

i had the same issue but i solved that by adding this code to force facebook to scrape my page it worked for me

FB.api("", 'post', { id: 'YourLinkToShare', scrape: 'true' }, function () {"YourShareMethodHERE'; });

try it and let me know ;)

Gergo Erdosi
  • 40,904
  • 21
  • 118
  • 94