2

I'm developing a web app where users can get coupons and similar things. I need to publish with Open Graph using the Javascript sdk an action each time an user choose and request a coupon.

When you click a coupon it will redirect you to the page coupondetail.php?cid=248 (Where "Cid" is the Coupon ID ). Actually I personalize the og meta tags with PHP: In this way Facebook should scrape a different content for each ?cid shared.

This is actually the way I personalize them using PHP: (Mycouponapp is a sample name!).

  <head>
    <meta charset="ISO-8859-1">
    <title>Coupons</title>
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-US" xmlns:fb="https://www.facebook.com/2008/fbml"> 
<head prefix="og: http://ogp.me/ns# mycouponapp: 
                  http://ogp.me/ns/apps/mycouponapp#">
  <meta property="fb:app_id" content="*appid*" /> 
  <meta property="og:type" content="mycouponapp:reward"/> 
  <meta property="og:title" content="<?php echo $couponname; ?>" /> 
  <meta property="og:image" content="http://www.mycouponapp.com/<?php echo $couponimgurl; ?>" /> 
  <meta property="og:description" content="<?php echo $couponname; ?>" /> 
  <meta property="og:url" content="http://www.mycouponapp.com/coupondetail.php?cid=<?php echo $cid; // coupon id ?>">

Ten days ago I was testing the website and I set a static og:title, calling it "Sample Reward". Even if I changed the code, today when I publish an action using Javascript it still shows "Matteo got Sample Reward on Mycouponapp", instead of showing "Matteo got couponname on Mycouponapp".

I already used the Facebook debugging tool to try scraping again the content, but it doesn't work (Even if the debugging tool shows a correct Coupon detail!)

Also, if I click of the "Sample Reward" text I will be redirected to http://www.mycouponapp.com/coupondetail.php?rid= and as you can see there is not Cid at the end.

I really can't understand why. I clip my JavaScript code: Maybe the problem is on that! The Facebook JS SDK was already loaded before this.

<script>
 function postCoupon()
  {

   FB.login(function(response) {
   if (response.authResponse) {

      FB.api(
        '/me/_AppName_:get?reward=http://www.mycouponapp.com/coupondetail.php?cid=<?php echo $rid; ?>',
        'post',
        function(response) {
           if (!response || response.error) {
              console.log(response.error);
           } else {

              alert('Pook was successful! Action ID: ' + response.id);
           }
        });
        }
 }, {scope: 'publish_actions'});


  }
  </script>

  <script>
    window.fbAsyncInit = function() {
      FB.init({
        appId      : '_App Id_', // App ID
        status     : true, // check login status
        cookie     : true, // enable cookies to allow the server to access the session
        xfbml      : true  // parse XFBML
      });
    };



  </script>

What's wrong in my code? Thanks!

4

1 回答 1

2

此时,最好的办法可能是将您的 url 方案更改为类似这样的方式,mycouponapp.com/coupondetail/248以便每张优惠券都有一个唯一的 url。

您可以通过在 .htaccess 文件中重写 url 或更改 PHP 应用程序的 url 方案来做到这一点。

于 2012-06-21T00:35:43.527 回答