Solved

Share post from Facebook Tab Application

Posted on 2014-01-18
6
41 Views
Last Modified: 2016-05-17
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
Comment
Question by:NickTERiS
6 Comments
 

Author Comment

by:NickTERiS
ID: 39792490
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
 
LVL 109

Accepted Solution

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
PHP error function not working on AWS 10 71
Restricting the scope of variables to private in OOP 4 22
jQuery force form POST 7 46
if (is_singular not working 5 18
JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo‚Ķ
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

860 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