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

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!

Related

Get post-id after FB.ui() share

I need to get post-id after user clicks on the share button. My code so far:
$("#share").click(function(e) {
e.preventDefault;
FB.ui({
method: 'share',
href: 'developers.facebook.com',
}, function(response){
if(response && !response.error_code) {
console.log(response); // => []
} else {
alert('err');
}
});
});
After content is successfully shared, the response I get is an empty array with no data. How can I get the post-id of share post?
Check out the docs for information about the response:
Only available if the user is logged into your app using Facebook and has granted publish_actions. If present, this is the ID of the published Open Graph story.
Meaning, you will only get the post-/object-id if the user is authorized with the publish_actions permission.

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

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?

Redirect to page with add page tab dialog

Facebook recently notified they are deprecating support for app profile pages.
Apps created after Dec 10th no longer have the app page option, together with the
"add to my page" functionality, and must use the new Add page tab dialog.
After the user selects which page to add the application to, is there any way to
redirect the user to the selected page?
Similar functionality existed in the "old" add to page dialog, e.g.
https://www.facebook.com/add.php?api_key=MY_ADD_ID&pages=1
Activating the dialog with a response function seems to bring no result.
`
// Add app to page
function addToPage() {
// calling the API ...
FB.ui({
method: 'pagetab',
redirect_uri: 'MY_URL',
},function(response) {
alert(response);
});
}
`
So, two questions:
a) Is there any possibility for the app using the dialog to "know" which page was selected?
b) Is there any way to redirect the user to the selected page.
Thx!
<script type="text/javascript">
function addToPage() {
// calling the API ...
FB.ui(
{
method: 'pagetab'
},
function(response) {
if (response != null && response.tabs_added != null) {
$.each(response.tabs_added, function(pageid) {
alert(pageid);
});
}
}
);
}
</script>
Use above code...you will get page id of pages selected by the user
but what if the user has a custom name for its page.
i modify devson.. code a bit
FB.ui(
{
method: 'pagetab',
redirect_uri: '',
},
function(response) {
if (response != null && response.tabs_added != null) {
$.each(response.tabs_added, function(pageid) {
FB.api(pageid, function(response) {
alert('redirect to ' + response.link);
});
});
}
}
);
This used to be simple, using the facebook UI.("Add to My Page") Unfortunately facebook removed this.
You can add it using www.facebook.com/dialog/pagetab?app_id=YOUR_APP_ID&next=YOUR_URL
I put this an html and publisched it below. Just visit, enter your app params, hit submit, and our done.
http://www.jibecompany.com/2012/add-a-facebook-page-tab-application-to-your-page

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');
}
});

Facebook Request 2.0

I am kind of confused on how to use the new facebook request dialog box. Using the below mentioned function opens a box and I am able to send the request to the user who receives it. But when the user clicks on the request nothing happens instead the user is redirected to an internal link:
http://www.facebook.com/?request_ids=105890902828361%2C105893002828151%2C105899456160839%2C105902046160580%2C105904092827042&notif_t=app_request
How to resolve the issue? (Canvas Page not defined in Settings but Canvas Url is)
function requestsDialog()
{
FB.ui({
method: 'apprequests',
message: 'Here is a new Requests dialog...',
title: 'example',
data: 'trackinginfo'
},
function(response) {
if (response) {
alert('Request was sent.');
} else {
alert('Request was not sent.');
}
}
);
};
You need to specify a Canvas Page. For example, if your canvas page is:
http://apps.facebook.com/test_application
Then the URL that user will go to when clicking on the request will be:
http://apps.facebook.com/test_application?request_ids=12020393994,129193929392
At which point you can use the Graph API to look up what the requests are using the id (documentation here)