Facebook Share Dialog, user message not being passed through - facebook

Having issues getting the Share Dialog to work properly. My code is as follows (in slim):
doctype html
html
head
title test page!!!
javascript:
window.fbAsyncInit = function () {
FB.init({
appId: 'xxx',
xfbml: true,
version: 'v2.2'
});
};
(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'));
body
h1 Facebook custom share button test
a href='#' Testing!!
javascript:
document.getElementsByTagName('a')[0].addEventListener('click', function() {
FB.ui({ method: 'share', href: 'http://www.washingtonpost.com' }, function(resp) {});
return false;
});
My app setting on Facebook (development app) are setup correct (Site URL is set to http://localhost:3000/).
In summary, everything works except for the message that the user can type into the dialog here:
That value never shows up when the post reaches the user's timeline feed:
I think I'm following the documentation correctly. What am I missing?

This appears to be a bug in sdk!
https://developers.facebook.com/bugs/395435640603415/

Related

Send-to-messenger plugin not showing

My Send-to-messenger plugin is not appearing on my website.
Here is my config:
<script>
window.fbAsyncInit = function() {
FB.init({
appId : 'xxxxx',
autoLogAppEvents : true,
xfbml : true,
version : 'v3.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 = "https://connect.facebook.net/en_US/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>
<div class="fb-send-to-messenger"
messenger_app_id="xxxxx"
page_id="vvvvv"
color="blue"
size="large">
</div>
The html generated by this code on this page: https://www.weekendr.eu/bonsplans seems ok, but the button would still not appear.
Some elements which may help :
I'm on prod env
My website has https: https://www.weekendr.eu
My app is published and online
I'm admin and connected to FB besides
I allow third-party cookies
Thanks !
I can see your code and found you are missing to subscribe event.
FB.Event.subscribe('send_to_messenger', function(e) {
// callback for events triggered by the plugin
});
Please find full code below :
<script>
window.fbAsyncInit = function() {
FB.init({
xfbml : true,
version : 'v3.2'
});
FB.Event.subscribe('send_to_messenger', function(e) {
// callback for events triggered by the plugin
console.log(e);
});
};
(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/xfbml.customerchat.js';
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>
<div class="fb-send-to-messenger"
messenger_app_id="<Your App ID>"
page_id="<Your Page ID>"
data-ref="1"
color="blue"
size="large">
</div>
In extra, you need to follow below steps before you write above code:
1) Add your domain into the white list (Go to your facebook page -> setting)
2) Create webhook in your server and write below code (Code is in PHP. You can use any language)
For node js: https://developers.facebook.com/docs/messenger-platform/getting-started/webhook-setup
<?php
if($_SERVER["REQUEST_METHOD"] == "POST") {
//Write code to listen webhook request
} else {
$VERIFY_TOKEN = '1234';
$mode = $_REQUEST['hub_mode'];
$token = $_REQUEST['hub_verify_token'];
$challenge = $_REQUEST['hub_challenge'];
if ($mode && $token) {
// Checks the mode and token sent is correct
if ($mode === 'subscribe' && $token === $VERIFY_TOKEN) {
// Responds with the challenge token from the request
console.log('WEBHOOK_VERIFIED');
echo $challenge;
http_response_code(200);
} else {
// Responds with '403 Forbidden' if verify tokens do not match
http_response_code(403);
}
} else {
http_response_code(403);
}
}
?>
3) Goto apps settings and verify your webhook
Setting URL :
https://developers.facebook.com/apps/<Your App ID>/messenger/settings/
Now you should be able to view the "Send to Messenger" button
Note: If app is in development then Admin, developer & tester can only see this button.
You need to whitelist your domain (https://www.weekendr.eu) in the Messenger Profile for your page:
https://developers.facebook.com/docs/messenger-platform/reference/messenger-profile-api/domain-whitelisting
I'm assuming you are replacing all the xxx and vvv with your actual app ID and Page ID, as well.
In my case, the issue is because my Ad blocker (uBlock) blocks the call to facebook. Disabling uBlock solve the issue.

Change bold black caption in Facebook's sharing dialog

Is there a parameter to change the bold black text (text "Google" in the example below) in Facebook's sharing dialog? If yes, which one?
My code:
window.fbAsyncInit = function() {
var locationArray = window.location.href.split("/");
FB.init({
channelUrl: locationArray[0] + '//' + locationArray[2] + '/channel.php', //custom channel
xfbml : true,
version : 'v2.6'
});
}
function test(){
alert("test");
FB.ui(
{
method: 'share',
name: 'Sharing Test Name',
caption: 'Sharing Test Caption',
//picture: 'http://4.bp.blogspot.com/-8BR3- K0b_lI/VlZ6b3WCM5I/AAAAAAAARmA/ATbes06U8oU/s1600/mustache-smiley.jpg',
description: "Post to test the sharing funtion available via Facebook's js sdk",
href: 'https://google.de',
},
// callback
function(response) {
if (response && !response.error_message) {
alert('Posting completed.');
} else {
alert('Error while posting.');
}
}
);
}
<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/de_DE/sdk.js#xfbml=1&appId={{ fbAppId }}&version=v2.5";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
<div onclick="test()">share</div>
Research didn't return anything for me (Facebook's docs, here, Google). Is Facebook not allowing to change that part of the dialog text?
There used to be parameters to control this, I may be mistaken however currently I think the only way to do this is using the Open Graph meta tags.

React JS loading FB share

I'm trying to add a facebook share to my react application. There is a lot of detail on Stackoverflow around adding FB.XFBML.parse()
How ever i'm a lint error "FB is not defined". What is the best way to load FB?
edit
window.fbAsyncInit function added.
"use strict";
var React = require('react');
var Router = require('react-router');
var Link = Router.Link;
var ThanksPage = React.createClass({
componentDidMount: function() {
(function (d, s, id) {
const fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {
return;
}
const js = d.createElement(s); js.id = id;
js.async = true;
js.src = '//connect.facebook.net/fr_CA/sdk.js';
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
window.fbAsyncInit = function() {
FB.XFBML.parse();
};
},
render: function() {
return (
);
}
});
module.exports = ThanksPage;
You can only use FB after FB.init:
componentDidMount() {
window.fbAsyncInit = function() {
//SDK loaded, initialize it
FB.init({
appId : 'your-app-id',
xfbml : true,
version : 'v2.6'
});
//JS SDK initialized, now you can use it
FB.XFBML.parse();
};
//load the JavaScript SDK
(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'));
}
Also, make sure to use this with a server (public or localhost), don´t just open the html file in your Browser. You should also consider putting the Facebook stuff in a separate file, so you can use it in future projects. But first, make sure it works and make sure you understand what´s happening.
Keep in mind that you may need to use FB.XFBML.parse in componentDidUpdate too. You have to make sure the JS SDK is loaded already for that. componentDidMount will only get called once, and if you go to another route and back to this component, it will be cached and you need to parse Social Plugins again.
More information about the JS SDK: http://www.devils-heaven.com/facebook-javascript-sdk-login/
You can get rid of the linting error by using /*global FB*/ at the head of your files, or (much better) by defining FB in the .eslintrc file (if using ESLint):
"globals": {
"FB": true
}
You are trying to execute
FB.init();
FB.XFBML.parse();
When the SDK is not even loaded, so, of course, you will get the undefined reference error.
You are missing the callback
window.fbAsyncInit = function() {
// Example: Standard initialization code:
FB.init({
appId : '{your-app-id}',
status : true,
xfbml : true,
version : 'v2.4' // or v2.0, v2.1, v2.2, v2.3
});
FB.XFBML.parse();
};
This code loads the SDK asynchronously so it does not block loading
other elements of your page. This is particularly important to ensure
fast page loads for users and SEO robots.
The URLs in the above code are protocol relative. This lets the
browser to load the SDK over the same protocol (HTTP or HTTPS) as the
containing page, which will prevent "Insecure Content" warnings.
The function assigned to window.fbAsyncInit is run as soon as the SDK
is loaded. Any code that you want to run after the SDK is loaded
should be placed within this function and after the call to FB.init.
For example, this is where you would test the logged in status of the
user or subscribe to any Facebook events in which your application is
interested.
Furthermore, you should set the callback before loading the SDK
window.fbAsyncInit = function() {
// Example: Standard initialization code:
FB.init({
appId : '{your-app-id}',
status : true,
xfbml : true,
version : 'v2.4' // or v2.0, v2.1, v2.2, v2.3
});
FB.XFBML.parse();
};
(function (d, s, id) {
const fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {
return;
}
const js = d.createElement(s); js.id = id;
js.async = true;
js.src = '//connect.facebook.net/fr_CA/sdk.js';
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
If you want to add any social share buttons to your react pages then you can try out npm module react-share which is very easy compared to native APIs by FB, Twitter etc.
Sample react-share code snippet at https://samvikshana.weebly.com/blog/react-share-social-share-widgets

Facebook Javascript SDK: getLoginStatus getting no response

As instructed by this page, I include the SDK snippet into my page, except that since I don't have any Facebook APP and I was just trying to build a custom share button on my page, I leave parameter "app-id" as null. To test if it is up and running, on console I execute
FB.getLoginStatus(function(response){
console.log(response)
})
while I am logged in FB. However, it returns undefined, which means there is no response. What is wrong? Is this because I didn't assign a "app-id"?
It depends on where you're calling getLoginStatus from and in what order. It needs to be inside your fbAsyncInit function:
window.fbAsyncInit = function() {
FB.init({
appId : 'your-app-id',
xfbml : true,
version : 'v2.4'
});
FB.getLoginStatus(function(response){
console.log(response);
});
}
(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'));
That should load the SDK, initialize everything, then get your login status.

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!