Solved

Facebook Graph Issue with Dynamic PHP Site

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

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
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…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

778 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