Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 349
  • Last Modified:

Facebook Graph Issue with Dynamic PHP Site

Hi,

I have a PHP-driven website that has a search capability of items. Each item is shown in the search result and has facebook sharers for each of them. Once you click on the item, it shows the items details. Once you click on the Facebook sharer for the item, it "should" share the items detail and image.

I have followed the Facebook Graph instructions but I am running into an issue:

1) When you click on the facebook sharer for item A on the Search Result, the facebook sharer pops up showing the correct image for Item A and description (which are passed as variables)
2) Once it gets posted in the Wall, it does not show the correct image for Item A (although the link and description is correct)

We believe that is randomly picking an image from Item A's description page instead of the image variable we passed.

Does anybody know what could we be missing? In short we want to share the correct image (through a variable) by clicking on the Item's sharer in a search result. See screenshot

This is a hard one but any help is appreciated! Thank you!!
0
ArgieIT
Asked:
ArgieIT
1 Solution
 
Ray PaseurCommented:
Screenshot?

FB Like and Share are seemingly an endless work in progress, and FB changes this without notice.  The only dependable and consistent thing I've found has been a Like button that is the only FB button on the page, and the page must contain only one image.  In other words, I've found that this works if you create a separate page for each item.

Here's my sample from a recent WordPress function.  It should be pretty up-to-date.

/**
 * CREATE A SHORTCODE THAT DISPLAYS A FACEBOOK "LIKE"
 * REF: http://speckyboy.com/2011/07/18/getting-started-with-wordpress-shortcodes-examples/
 * REF: https://developers.facebook.com/docs/plugins/like-button/
 */
function facebook_link()
{
    // GET THE CURRENT PROTOCOL
    $pro = (empty($_SERVER['HTTPS'])) ? 'http' : 'https';

    // GET THE CURRENT PAGE
    $uri = $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];

    // NOTE: THE LINK MUST NOT BE URLENCODED
    $lnk = $pro . '://' . $uri;

    // INCLUDE THE FB SDK (SHOULD PROBABLY BE SOMEWHERE ELSE IN THE TEMPLATE?)
    $sdk = <<<SDK
<div id="fb-root"></div>
<script>(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_US/all.js#xfbml=1";
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
SDK;

    // INCLUDE THE BUTTON WITH THE LINK
    $div = <<<DIV
<div class="fb-like" data-href="$lnk" data-layout="button_count" data-action="like" data-show-faces="false" data-share="false"></div>
DIV;

    return $sdk . $div;
}

Open in new window

0
 
ArgieITAuthor Commented:
Thanks, unfortunately I cant share a screenshot due to NDA restrictions but I do appreciate the effort in attempting to answer the question. I will have to keep investigating cause there is no way I can have only one photo in the page that we are trying to share. Thanks again
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now