Solved

Facebook Graph Issue with Dynamic PHP Site

Posted on 2014-01-20
2
341 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 110

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

Independent Software Vendors: 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!

Question has a verified solution.

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

Suggested Solutions

This article discusses four methods for overlaying images in a container on a web page
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

749 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