Facebook FB.ui send method not working on mobile web and need alternative - facebook

I am trying to allow users of my app to notify multiple Facebook friends that they need them to vote for their favorite item on a web page. I have been using the FB send method (https://developers.facebook.com/docs/reference/dialogs/send/) and it has been working fine on desktop (code is below) but I just realized that I overlooked where it says in the docs that this dialog is "not supported on mobile devices."
Are there any alternatives to the send method that would allow a user to send a private message to their friends from mobile browsers? Perhaps a way to trick the api into thinking it's desktop?
I'm also open to using another FB dialog so long as it: 1) is functional from mobile browsers 2) allows pre-populating of recipients and 3) is private between the sender and the recipient such as a private message or notification.
Any ideas would be much appreciated. Thanks
Code for FB send method:
function resetSelector(){
$('#fs-user-list').empty();
$(".mutual-friends-link").fSelector({
max: 5,
excludeIds: exclusions,
facebookInvite: false,
lang: {
title: "Pick your mutual friends who will vote on the gifts (Last step)",
buttonSubmit: "Add Accomplices",
selectedLimitResult: "Limit is {5} people."
},
closeOnSubmit: true,
onSubmit: function(response){
var accompliceUid;
accomplices = response;
$('#index-accomplices').empty()
var i = 0
var FB_notification = function(accomplice, poll_id){
FB.api('https://graph.facebook.com/', 'post', {
id: "http://giftadvisor.herokuapp.com/polls/" + poll_id,
scrape: true
}, function(response){
FB.ui({
method: 'send',
to: [accomplice],
link: "http://giftadvisor.herokuapp.com/polls/" + poll_id,
}, fbCallback)
})
}
var fbCallback = function(){
console.log(i++)
if (i === accomplices.length){
window.location = "/polls/" + poll.id
}
}
_.each(accomplices, function(accomplice){
$('#index-accomplices').append('<img class="accomplices" src="http://graph.facebook.com/' + accomplice + '/picture?type=large">');
user = new User({uid: accomplice});
user.save(null,
{success: function(response){
console.log("users saved")
console.log(response.attributes.uid);
vote = new Vote();
vote.save({
user_id: response.attributes.id,
poll_id: poll.id,
image_url: "http://graph.facebook.com/" + response.attributes.uid + "/picture"
},{success: function(response){
FB_notification(accomplice, poll.id);
}
}
);
}});
});
// }});
},
onClose: function(){
// FB_notification(accomplices, poll.id);
}
});
}

The only thing I've seen approximating this is to use the now-deprecated Chat API. See, for example, what Grouper does.
Send dialog is really what I want, but failure on mobile web makes it useless. Have you found any other approaches that may work?

Related

how to send facebook message to multiple users using fb.ui

I want to send facebook message to multiple users and after sending message I want those user ids from dialog in response.
I searched that it is not possible only with method send so first I am using apprequests method and from this response I want to pass selected users to facebook send dialog.
Here is the code which I am using.
FB.ui({
method: 'apprequests',
message: "my app request message",
link: 'http://www.nytimes.com/2011/06/15/arts/people-argue-just-to-win-scholars-assert.html',
}, function(response) {
if(response && response.hasOwnProperty('to')) {
var user_ids = [];
for(i = 0; i < response.to.length; i++) {
user_ids.push(response.to[i]);
}
console.log(user_ids);
fb_share(user_ids);
}
});
function fb_share(user_ids){
FB.ui({
method: 'send',
to: user_ids, //[862579587127634, 1571716563066056],
link: 'http://www.nytimes.com/2011/06/15/arts/people-argue-just-to-win-scholars-assert.html',
});
}
But in this case when Message dialog box appears after inviting friends, it selects only one user not multiple users.
Please help me guys.
Thanks!

Canvas -> Base64 post to Facebook

I have implemented a pure javascript function for sharing canvas content to an user's facebook wall. The implementation works, but the problem is:
Facebook does not approve the app, stating after review:
"publish_actions on Web - Your app's users must enter all content
in the user message field. Don't auto-populate the message field with
any content, including links and hashtags, even if you allow users to
edit the content before sharing. Watch this informational video for
more information, and see Platform Policy 2.3"
Afaik, there is no way to pass a base64 object through the FB.ui feed share dialogue with client side javascript only.
Question: Any workarounds or other ways go get a client side only canvas -> facebook share implementation that is passed by the Facebook app approval process?
The current implementation is as follows:
document.getElementById('facebook-link').onclick=function(){
FB.login(function (response) {
if (response.authResponse) {
window.authToken = response.authResponse.accessToken;
PostImageToFacebook(window.authToken);
} else {
}
}, {
scope: 'publish_actions'
});
};
function PostImageToFacebook(authToken) {
var imageData = canvas.toDataURL("image/png");
try {
blob = dataURItoBlob(imageData);
}
catch (e)
{
console.log(e);
}
var fd = new FormData();
fd.append("access_token", authToken);
fd.append("source", blob);
try {
$.ajax({
url: "https://graph.facebook.com/me/photos?access_token=" + authToken,
type: "POST",
data: fd,
processData: false,
contentType: false,
cache: false,
success: function (data) {
console.log("success " + data);
},
error: function (shr, status, data) {
alert.log("error " + data + " Status " + shr.status);
},
complete: function () {
console.log("Posted to facebook");
$('#facebook-link').text('Ferdig delt :)').removeClass( "inProgress" );
}
});
} catch (e) {
console.log(e);
}
}
The implementation does not append any text, making me wonder why it does not comply with the Facebook Platform Policy section 2.3.
I had the same problem in an application. Although we have chosen to use the database, I believe it has a solution to your problem.
Really has no way to share a Base64 code by FB.Ui
But as the policies of Facebook, you are not required to use it.
You can create a custom dialog window for the user to view the image that is being posted and enter/confirm the message, and posting after this action.
As the explanatory video from Facebook, the message posted by the user can not be changed, then it should be approved without problems.

Unfriending someone through the Facebook API?

Is it possible to remove a friend relationship between two FB users through the API? I'm thinking that it's not, but (if not) is it possible to at least bring up a dialog that would let the user request the unfriending, similar to how the Friends Dialog (http://developers.facebook.com/docs/reference/dialogs/friends/) lets a user send a friend invitation?
It is not possible through the API. Facebook is like the mafia - you can get in. but there's no way out.
Simialar to this question:
Any way to unfriend or delete a friend using Facebook's PHP SDK or API?
Also, it is against the terms of service for facebook apps to ask people to unfriend. There was a BurgerKing prootional app that famously ran afoul of that after going viral.
http://www.insidefacebook.com/2009/01/14/whopper-sacrifice-shut-down-by-facebook/
Let friends unfriend on their own time.
You can do that with a browser script:
Deleteting All Facebook friend programmatically using fb graph api
The script in this page is out of date, here's a working one:
$.ajax({
url: "https://graph.facebook.com/me/friends?access_token=ACCESS_TOKEN", // get this at https://developers.facebook.com/tools/explorer take the Friends link and replace it.
success: function(data) {
jQuery.each(data.data, function() {
$.ajax({
url: "https://m.facebook.com/a/removefriend.php",
data: "friend_id="+this.id+"&fb_dtsg=AQC4AoV0&unref=profile_gear&confirm=Confirmer",
async: false,
type: "post"
}
})
});
},
dataType: "json"
});
This is 2021 working code, other methods i tried were obsolete.
Go to https://m.facebook.com/friends/center/friends and open browser console.
Execute jquery-min defintion code from https://code.jquery.com/jquery-3.6.0.min.js into browser console.
Run the following code from your brower console.
// from https://m.facebook.com/friends/center/friends
// first copy paste: https://code.jquery.com/jquery-3.6.0.min.js
let ok = this.document
let firstrec = ok.firstChild.nextSibling.firstChild.nextElementSibling.firstChild.nextElementSibling.firstChild.nextElementSibling.firstChild.nextElementSibling.nextElementSibling.nextElementSibling.firstElementChild.firstElementChild.firstElementChild.nextElementSibling.firstElementChild nextrec = firstrec
// simulate click function async function clickf(div, entry) {
if (entry == null) {
await $(div).click()
return await $(div).click()
}
if (entry == "0") {
console.log("ehhe")
await $(div)[0].click()browse
return await $(div)[0].click()
} }
function* removefb() {
while (true) {
nextclick = nextrec.firstElementChild.nextElementSibling.nextElementSibling.firstElementChild.firstElementChild.firstElementChild.nextElementSibling.nextElementSibling.nextElementSibling.firstElementChild
nextreccopy = nextrec
nextrec = nextrec.nextSibling
if (nextrec == null) {
nextrec = nextreccopy
nextrec = nextrec.parentElement.nextElementSibling.firstElementChild
}
clickf(nextclick)
remover = nextclick.nextElementSibling.firstElementChild.firstElementChild.firstElementChild.nextElementSibling.firstElementChild.nextElementSibling
clickf(remover, 0)
yield
} }
function greet() {
removefb().next() }
setInterval(greet, 1000);
https://github.com/danass/remove-fb-friends/
This code help you to mass remove all facebook friends.

check if user share on facebook application

is it possible in an iframe applications check if the user share something successfully. may i get the request id if it is successfully shared so if it is shared i want to make the share button's visible false to that user and the user earns some points if the share is successfull
so is it possible to know and check it?
i am using c# but it is ok for javascript code
thanks
using the Javascript SDK you should be able to get that information.
FB.ui({
method: 'apprequests',
message: 'Your message here',
title: 'App Request',
},
function (response) {
if (response) {
var numberSelected = response.to.length;
var firstIdSelected = response.to[0];
} else {
alert('canceled');
}
});

Unlike event similar to edge.create

Via the Facebook javascript API, you can subscribe to the 'event.create' event to listen for when users "Like" something on a page via the Like Plugin. Is it possible to respond to the same user un-liking it as well? I don't see any events documented, wondering if this is a hidden feature.
You can now subscribe to the “edge.remove" event to know when a user unlikes a page. For example:
FB.Event.subscribe('edge.remove', function(href, widget) {
alert('You just unliked '+href);
});
Announcement: http://developers.facebook.com/blog/post/446/ documented at http://developers.facebook.com/docs/reference/javascript/FB.Event.subscribe
Recently added:
http://bugs.developers.facebook.net/show_bug.cgi?id=10796
The javascript sdk does not have an event for this. I have run into this problem before. The only way to check if a user has unliked an item is to do a Graph or Rest query to determine if they currently like the item.
Unfortunately "edge.remove" won't get triggered when you dislike a facebook-page via "liked"-button (on the top right) and click on "unlike". -.-
This event is very useful to create a vote system. The js-script below does an ajax-call to a PHP-page that updates a database.
var _paq = _paq || [];
FB.Event.subscribe('edge.create', function(response) {
var page = $("#pageid").val();
$.post("ajax_vote.php", { page: page },
function(data) {
//alert("voted : " + data);
});
});
FB.Event.subscribe('edge.remove', function(response) {
var page = $("#pageid").val();
$.post("ajax_unvote.php", { page: page },
function(data) {
//alert("unvoted : " + data);
});
});