Go Premium for a chance to win a PS4. Enter to Win

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

Share post from Facebook Tab Application

I've a forum script which works as Facebook Tab Application. I want to add a Share button for each post. The strange is that the code below was working at least when I tried it for last time at Oct 2013.
$post["fb_title"] = urlencode($post["threadtitle"]);
$link_params = array('postid' => $post["id"]);
$encodedParams = urlencode(json_encode($link_params));
$post["fb_url"] = urlencode('https://www.facebook.com/pages/Faceforo/app_XXXXXXXXXXXXX?app_data=').$encodedParams;
$post["fb_summary"] = urlencode(strip_tags($post["bodytext"]));
$post["fb_image"] = urlencode("https://www.faceforo.com/demo/forum/photos/".$photo["photoname"]."");

Open in new window

And in the template file I've the code:
<a onClick="window.open('http://www.facebook.com/sharer.php?s=100&amp;p[title]={$post.fb_title}&amp;p[summary]={$post.fb_summary}&amp;p[url]={$post.fb_url}&amp;p[images][0]={$post.fb_image}','sharer','toolbar=0,status=0,width=548,height=325');" href="javascript: void(0)">Share to Facebook</a>

Open in new window


Now, the only that is posting in my Timeline is a link, which is wrong:
https://www.facebook.com/pages/Faceforo/app_685940788093351?app_data={"postid":"2"}

Open in new window


A notice: Since the time that I have tested it and found it working I've changed Hosting Provider. Maybe my PHP configuration needs something?

Thank you
0
NickTERiS
Asked:
NickTERiS
1 Solution
 
NickTERiSAuthor Commented:
I was able to solve the half problem by using Feed dialog instead of share. PHP code remains the same, only the Link must be:
<a onClick="window.open('https://www.facebook.com/dialog/feed?app_id=xxxxxxxxxxx&link={$post.fb_url}&picture={$post.fb_image}&name={$post.fb_title}&caption={$post.fb_title}&description={$post.fb_summary}&redirect_uri=https://apps.facebook.com/faceforo/popup_close.html&display=popup','sharer','toolbar=0,status=0,width=548,height=325');" href="javascript: void(0)">Share to Facebook</a>

Open in new window


The only that left out is: Does Feed dialog supports app_data as Share?
0
 
Ray PaseurCommented:
Not sure this is all that helpful, because I don't really know the extent of your requirement, but I can show you what FB is publishing now.  I've used it successfully on a WordPress site.  If you read the FB man page shown in the comments you will find other options.

/**
 * 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

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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