Solved

Share post from Facebook Tab Application

Posted on 2014-01-18
6
64 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
[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
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 110

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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

626 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