Solved

Facebook Graph Issue with Dynamic PHP Site

Posted on 2014-01-20
2
335 Views
Last Modified: 2014-02-04
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
Comment
Question by:ArgieIT
2 Comments
 
LVL 108

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 39796514
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
 

Author Closing Comment

by:ArgieIT
ID: 39834577
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Owning a franchise can be the dream of a lifetime. It provides a chance for economic growth. You can be as successful as you want.  To make your franchise successful, you need to market it successfully. Here are six of the best marketing strategies …
Find out what you should include to make the best professional email signature for your organization.
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now