Facebook Messenger Chat Plugin not Firing messaging_referrals event in Webhook Request - facebook

I'm trying to integrate messenger on my website. I want to track users (by Cookie Value). There is a option in Facebook Chat Plugin, "messaging_referrals" which tells referral key of user chatting.
As per instructions i have added event "messaging_referrals" in facebook app webhook events.
But still in my webhook i'm not getting referral key.
My Plugin Code looks like this
<div class="fb-customerchat"
page_id="ABC"
ref="OPTIONAL_WEBHOOK_PARAM"
logged_in_greeting="<GREETING_MESSAGE_FOR_LOGGED_IN_USERS>"
logged_out_greeting="<GREETING_MESSAGE_FOR_LOGGED_OUT_USERS>">
</div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : 'XYZ',
autoLogAppEvents : true,
xfbml : true,
version : 'v2.11'
});
};
(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 = "https://connect.facebook.net/en_US/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>
And Request I'm getting in my webhook is this
"data": {
"sender": {
"id": "abc"
},
"recipient": {
"id": "ABC"
},
"message": {
"mid": "mid.$cAADv109V6n_F6BY",
"text": "hi",
"seq": 511,
"tags": {
"source": "customer_chat_plugin"
}
},
"timestamp": 1522049646776
}
As per this i should also be receiving "OPTIONAL_WEBHOOK_PARAM" in my webhook request

Here is how the ref field work in facebook.
MAKE SURE YOU HAVE REMAINED YOUR CHAT CONVERSATION HISTORY
THEN YOU FOLLOW THIS INSTRUCTION.
You must logout the current facebook , if you have.
you open your chat messenger within your website , THEN by click Login into Messenger button , will pop the Facebook login form for you, so just fill it and login.
After step 2, you will see in your website messenger box appear with button Continue as YOUR_FB_NAME Then you click this button, then the ref field will trigger .
Here is my log for proof as answer ( I am using SDK version 7.0) .
In your HTML customer chat might be look like this
<!-- Your Chat Plugin code -->
<div class="fb-customerchat"
attribution=setup_tool
page_id="11xx695540xxxx"
ref="your-ref-pass-to-webhoooks"
theme_color="#DA615C"
referer_uri="your-website-uri"
logged_in_greeting="Question-1"
logged_out_greeting="Question-2">
</div>

Related

FB.Event.subscribe("comment.create") fires but returns 500 when commenting first successful when replying

FB comment plugin gives 500 error. FB.Event.Subscribe("comment.create',callback) is fired but does not return successfully instead throws a 500 error.However,this only happens on the first comment.The post still goes through and appears as comment on page reload.
However,on the same post,when replying to the posted comment,it fires the event without any errors.
I am using facebook comment plugin and my setup is that i create dynamic url by getting data from the database and then create url based on that on front end.I am using knockout on the front end and flask at the backend.My goal here is to utilise FB comment plugin as threaded comment on each post.I am triggering push notifications when someone comments on the post by looking at the id of the post.
//HTML
<div data-bind="text:$data.location,
click:window.animateMarkerOnClick.bind($data), attr: { id:
$data.key,class:'search-list' }"></div>
<div id="listing-msg" >
</div>
<div class="fb-comments" data-bind='attr:{"href":
"http://localhost:8080/postit/get_share_listings/#" +
$data.key,"id":$data.key}' data-width="320" data-numposts="1" data-
colorscheme = "dark" notify = "true" data-order-by = "reverse_time"></div>
//JS EVENT SUBSCRIPTION
window.fbAsyncInit = function() {
FB.init({
appId : 'xxxxxxx',
autoLogAppEvents : true,
xfbml : true,
version : 'v3.2'
});
FB.Event.subscribe("comment.create", push)
};
(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 = "https://connect.facebook.net/en_US/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
//callback
function push(){
$.ajax({
type: "POST",
url: "http://localhost:8080/postit/push",
contentType: 'application/json;charset=UTF-8',
data:JSON.stringify({"data":document.activeElement.
parentElement.parentElement.parentElement.children[0].id})
})
}
As already stated,the event triggers callback but on first comment facebook
triggers url handler createComment which gives 500 but createReply successfully triggers the callback.
The comment.create event does not exist any more in the JS SDK.
https://developers.facebook.com/docs/reference/javascript/FB.Event.subscribe/v3.2 does not mention it any more, when you click the down arrow next to event, and https://developers.facebook.com/support/bugs/927463134113943/?comment_id=930637043796552 confirms it is gone: “comment.create is officially killed.”
You need to use server-side webhooks now, if you want your app to get notified about new comments made via the comments plugin, see https://developers.facebook.com/docs/graph-api/webhooks/reference/application/#plugin_comment

how to get my facebook wall with JS SDK

I'm testing a simple code to retrieve the last 5 posts from my personal facebook wall, then add them to the html with my personal css style. But I get only empty data! I'm using Graph API 2.3, on a web page.
I've created an app, called "cambiamentico". So I got the appid 421429864732436 and the secure code. My personal id, istead, is 100000007731737. NB - the app is not yet submitted for review, since it's only a test and doesn't work. Is it a problem?
If I ask, for example, "cocacolait/posts?limit=5", I get the 5 complete posts of that Page, but when I ask "100000007731737/?limit=5" I get only an empty data.
I guess there's some issue with permissions, maybe something called "access token" which I really don't know how to "make"... or find.
Here's the code:
window.fbAsyncInit = function() {
FB.init({
appId : '421429864732436',
xfbml : true,
version : 'v2.3'
});
testGetPosts();
};
(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/it_IT/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
function testGetPosts(){
//this work
FB.api('/cocacolait/posts?limit=5', function(response){
console.log(response);
});
//this, my private page (with public posts), doesn't work
FB.api('/100000007731737/posts?limit=5', function(response){
console.log(response);
});
}
Since you are fetching your own posts your app doesn't need to go through review.
And as you mentioned you are indeed missing an access token. If you are to fetch your posts from your Facebook wall you will need to make request to graph.facebook.com/me/feed?access_token = "access_token with read_stream permission"
To get access token go through: https://developers.facebook.com/docs/facebook-login/access-tokens#usertokens

Facebook Send UI renders empty window

I was just about to test something so I made 2 buttons with 2 links:
1.) using the facebook sharer.php functionality which works fine
2.) triggering the send ui using the URL redirect I took from the FB developers homepage:
http://www.facebook.com/dialog/send?app_id=123050457758183&link=http://www.nytimes.com/2011/06/15/arts/people-argue-just-to-win-scholars-assert.html&redirect_uri=https://www.bancsabadell.com/cs/Satellite/SabAtl/
I replaced the app id and both links with my own. My app is set up so it point to the links, since I know I had it running once before, where that was the problem.
Now as said the share button works perfectly fine but when I click one the other button I just see a white screen. The URL is in the address bar. Firebug shows no console errors and an empty head and body tag.
Any suggestions?
Thanks,
Gerd
UPDATE: I also implemented the regular javascript ui.send method. The window popsup. I am connected with facebook as the ssl seal shows but again nothing but white.
As far as the URL is concerned the URL is fine it is just a matter of time until Facebook allows to share a URL it has not indexed before. When I changed the link to my main domain instead of subfolder it worked.
As far as the JS SDK is concerned I forgot to check whether the user is logged in or not so this is how it works:
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : 'YourId',
xfbml : true,
version : 'v2.0'
});
};
(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/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>
<button onclick="sendFb()">Recommend JS</button>
<script type="text/javascript">
function sendFb(){
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
FB.ui({
method: 'send',
link: 'yourlink.com',
});
}
else {
FB.login(function(response) {
if (response.authResponse) {
FB.ui({
method: 'send',
link: 'yourlink.com',
});
}
else
alert('Not Authenticated!');
});
}
});
}
</script>
</body>
</html>

facebook share dialog (v2.0) does not promote user to login?

I am implementing a custom facebook share button with the new Facebook javascript SDK (v2.0 according to the docs in the developer center)
window.fbAsyncInit = function () {
FB.init({
appId: 'xxxxxxx',
xfbml: true,
version: 'v2.0'
});
};
(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/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
function shareToFacebook(url) {
var obj = {
method: 'share',
href: url,
};
function callback(response) { }
FB.ui(obj, callback);
}
$('#mb-facebook').click(function () {
shareToFacebook('http://some-url-to-share');
return false;
});
Now everything works fine exception one issue:
If I have logged into my facebook account before clicking the share to facebook button, then a popup window contains the expected facebook sharing form showed up, but if I do not log into my facebook account then click the share button, the a blank popup window contains nothing shows up, no promotion to log into facebook etc.
I do remember that I've done this before in another project that the share button will promote the user to log into facebook if he has not logged in yet.
So my question is : does facebook changed this behavior in the new SDK or I have missed something else?
Thanks in advance!

getLoginStatus always returns not_authorized

I am new to developing websites with Facebook SDK. So please bear with me.
Below is my simple code for verifying that I am logged into Facebook.
For some reason I always get the 'not_autherized' response, even though I am the only developer of my app. The app number I provide is correct.
<!DOCTYPE html>
<html lang="en">
<head>
</head>
<body>
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
// init the FB JS SDK
FB.init({
appId : 'censored app id', // App ID from the app dashboard
status : true, // Check Facebook Login status
cookies : true,
xfbml : true // Look for social plugins on the page
});
FB.getLoginStatus(checkLoginStatus);
function checkLoginStatus(response) {
if (response && response == 'connected') {
alert('User is authorized!');
} else {
alert('User not authorized!!!');
}
};
// Additional initialization code such as adding Event Listeners goes here
};
// Load the SDK asynchronously
(function(d, s, id) {
if (d.getElementById(id)) return;
var js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/all.js";
var fjs = d.getElementsByTagName(s)[0];
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>
</body>
</html>
Is there anything I have overlooked?
Much appreciated :)
A friend helped me with this. He very helpfully pointed out something that Facebook has neglected to document.
When you create a new facebook application, then it is NOT automatically authorized by the admin and developers. An authorized application is one that exists in the "Account Settings->Apps" list. If it is not in this list, then it is not authorized.
This means that you need to call FB.login() at some point in your code in order to popup the user authorization window.
Mind you, this should be called from a button. Otherwise, the popup could be blocked.
Hope this helps someone else but me.
Cheers :)