I'm having a problem passing my URL variables to the Facebook feed dialog. I can see it in the link when I press the button, but once I post it on Facebook, I get everything until the &
.
Here's my code:
<a href="https://www.facebook.com/dialog/feed?
app_id=142170752632916&
redirect_uri=http://domain.com/&
link=$currentUrl&
picture=http://fbrell.com/f8.jpg&
name=$title&
description=$description">Share</a>
$currentUrl = $_SERVER['REQUEST_URI'] ;
My URL looks like this:
www.Domain_Name.com/index.php?subaction=showfull&id=1368007502&start_from=3&template=Default&#disqus_thread
Once I post it on Facebook, I get the link as:
www.Domain_Name.com/index.php?subaction=showfull
And no id or other attributes are passed.
What can i do to fix it?
Edit:
Here's what I get once I try to post my link on the feed:
https://www.facebook.com/dialog/feed?%20%20app_id=142170752632916&%20%20redirect_uri=http://domain.com /&%20%20link=http://www.domain.com/FrontEnd/index.php?subaction=showfull&id=1368007502&start_from=3&template=Default&&%20%20picture=http://fbrell.com/f8.jpg&%20%20name=bbb&%20%20description=bbb
After looking at the facebook's documentation, seems like the real magic is in the callback function
function callback(response) {
document.getElementById('msg').innerHTML = "Post ID: " + response['post_id'];
}
This is the one that adds the additional paramenter ?post_id=12345
to the url https://mighty-lowlands-6381.herokuapp.com/
. Thus follow the example below that facebook provides ensuring the parameters in the callback function to the one that you want in your URL, namely subaction=showfull&id=1368007502&start_from=3&template=Default&#disqus_thread
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:fb="https://www.facebook.com/2008/fbml">
<head>
<title>My Feed Dialog Page</title>
</head>
<body>
<div id='fb-root'></div>
<script src='http://connect.facebook.net/en_US/all.js'></script>
<p><a onclick='postToFeed(); return false;'>Post to Feed</a></p>
<p id='msg'></p>
<script>
FB.init({appId: "YOUR_APP_ID", status: true, cookie: true});
function postToFeed() {
// calling the API ...
var obj = {
method: 'feed',
redirect_uri: 'YOUR URL HERE',
link: 'https://developers.facebook.com/docs/reference/dialogs/',
picture: 'http://fbrell.com/f8.jpg',
name: 'Facebook Dialogs',
caption: 'Reference Documentation',
description: 'Using Dialogs to interact with users.'
};
function callback(response) {
document.getElementById('msg').innerHTML = "Post ID: " + response['post_id'];
}
FB.ui(obj, callback);
}
</script>
</body>
</html>