Solved

Share post from Facebook Tab Application

Posted on 2014-01-18
6
29 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 108

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
PHP/Magento not logging 2 35
change password links 7 72
phpmyadmin 3 32
A form to still have contents even if some are wrong 10 46
Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
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)

912 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now