Solved

Share post from Facebook Tab Application

Posted on 2014-01-18
6
23 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
Comment Utility
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
Comment Utility
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

In this article, you will learn how to create custom audiences using your own email lists. You can use this custom audience as your target audience for advertising on Facebook. This allows you to advertise to your existing audience. Once you've crea…
Shoutout to Emily Plummer (http://www.experts-exchange.com/members/eplummer26.html) for giving me this article! She did most of it, I just finished it up and posted it for her :)    Introduction In a previous article (http://www.experts-exchang…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

762 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

13 Experts available now in Live!

Get 1:1 Help Now