Solved

Facebook Graph Issue with Dynamic PHP Site

Posted on 2014-01-20
2
330 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

747 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

9 Experts available now in Live!

Get 1:1 Help Now