I need to send to user's friends in facebook some link from my site or predefined message.
I got the list friends by this:
FB.api(
"/me/taggable_friends",
function (response) {
if (response && !response.error) {
console.log(response.data);
}
}
);
which is OK, I'm getting some friends.
At this question Send private messages to friends
author says I need so call method sendof API:
function facebook_send_message(to) {
FB.ui({
app_id:'xxxxxxxx',
method: 'send',
name: "sdfds jj jjjsdj j j ",
link: 'https://apps.facebook.com/xxxxxxxaxsa',
to:to,
description:'sasa d d dssd ds sd s s s '
});
}
It looks simple. Having friends as array of objects:
Object
id: "AaI7nqazWWHMkCjMrKNlvyFHWBRw......HFyppVJqjg4RBZurBg"
name: "Andre ...."
picture: Object
I hoped that I could to create array with id and use array in send-method of api in to:. But trying to start dialog I'm getting error "Bad param". The same if I use the name-property of object.
What do I do wrong ?
You can't pre-populate the list of recipients, Facebook messages are meant for user-to-user communication and not to invite people to an app or spam friends. It is not a good user-experience as well. The user should always choose the audience themselves.
I'd recommend you read the documentation for the Send dialog which contains all the information you need to make a point when communicating this to the project manager.
Related
I'm currently trying to get an idea of getting Facebook's RSVP for an event, but really stuck on that part:
as I see now, to get user's RSVP I have to make three requests with the following logic:
request eventID/attending/userID ->
if "data" array count == 0 ->
request eventID/maybe/userID ->
if "data" array count == 0 ->
request eventID/declined/userID
else -> means user didn't make any choice previously.
So here it looks like I have to make 3 requests to facebook's graph api to get users's RSVP for a single event.
The question is if there is any way to get an RSVP status for an event doing a single request?
I'm using the latest Facebook SDK and the latest graph api.
Many thanks in advance.
So the best solution here so far is:
one request to /eventID/attending/userID
one request to /eventID/maybe/userID
one request to /eventID/declined/userID (if needed to know if the event invitation was declined)
Call to eventID/attending(maybe/declined)/userID lets us filter rsvp to single user, so we avoid downloading and processing a large amount of data here.
After call you have two options:
If result is true, you get the following response:
{
"data": [
{
"name": "Oleskii Poplavlen",
"id": "10204715567996406",
"rsvp_status": "attending"
}
]}
If result is false, you get the following response:
{
"data": []
}
So while you still have to make multiple requests to get user's RSVP to event, you can avoid downloading loads of other users's rsvps.
Hope that helps someone!
I can get you started to do it in 2 calls:
FB.api('/'+ event_id + '?fields=id,attending{rsvp_status},maybe{rsvp_status}', function(event_response){
// here you should make a call to check if the user has the event and if so get the rsvp_status
FB.api('/'+ user_id + '/events?fields=id,rsvp_status', function(user_response){
// check if user has event, then log the rsvp_status
if(user_response.id == event_response.id) {
console.log(user_response.rsvp_status);
} else {
console.log("user is not going");
});
});
I have not tested this but I've been playing around with this API for quite a while now. This could be an answer to do it in 2 calls, not in 1 unfortunatly.
The first call doesn't need the 'attending' and 'maybe' fields but it's usefull to test with.
I read this article.
So, I tried it and I put a number in the data property.
FB.ui({
method: 'apprequests',
message: 'Come join me and play at MyWebSite!',
data: '12345',
redirect_uri: 'myWebSite'
});
I get the request_ids, but how do I get the data part (the 12345 number)?.
on server side, you can do something like:(using php here)
$request_ids = $_GET['request_ids'];
$request_ids = explode(",", $request_ids);
foreach($request_ids as $request_id)
{
$request_object = $facebook->api($request_id);
if(isset($request_object['data'])) $req_data = $request_object['data']; //$req_data will be '12345' as per your request data set.
// after getting the data, you may like to delete the request.
$full_request_id = $request_id."_".$fbid; //$fbid is current user facebook id
$facebook->api("$full_request_id","DELETE");
}
Did you try Facebook's documentation too?
https://developers.facebook.com/docs/requests/ has more documentation; if a data parameter was added in the call to the requests dialog, the same value should also be there when requesting the Request details via the API (i.e. a call to /REQUEST_ID)
See the facebook developer site documentation for more details
http://developers.facebook.com/docs/reference/dialogs/requests/
Note:
data:Optional, additional data you may pass for tracking. This will be stored as part of the request objects created. The maximum length is 255 characters.
In the context of a given Facebook app, suppose User A invited user B to start using it. Once User B accepts to use the app, is there any way to retrieve the ID of User A programmatically (via either PHP/JS SDK) ? This doesn't seem quite documented.
For what it's worth, A/B users are friends, if it's any use.
when user comes following the app request, you can get request id's using
$_GET['request_ids']
then retrieve all the request ids with which you can call graph api to get the corresponding request details like below:
if(isset($_GET['request_ids']))
{
$request_ids = $_GET['request_ids'];
}
$request_ids = explode(",", $request_ids);
foreach($request_ids as $request_id)
{
$request_object = $facebook->api($request_id);
//this $request_object have sender facebook id in the field uid_from
}
If you look here:
http://developers.facebook.com/docs/reference/dialogs/requests/
You can see the object layout. Of note is the data property:
Optional, additional data you may pass for tracking. This will be
stored as part of the request objects created. The maximum length is
255 characters.
In this object you can add your referring UserId and then when the request is claimed, you can then process it on your end.
Hope this helps.
Hi am using this function that works by a single ID (52000121) and comma separatted ID's (5000000,500002,500004,000002001)
function invite(id) {
FB.ui({method: 'apprequests',
message: '<?=get_texto_clave('wants_you_to_join')?>',
title: '<?=get_texto_clave('send_app_request')?> <?=$_SESSION['alias']?>',
to: id,
}, function(response){
if(response!=null){
var invitados = id.split(',');
for( i=0; i<invitados.length; i++){
$('#friend_'+invitados[i]).addClass('invited');
$('#friend_'+invitados[i]+' .inviteButton').addClass('invitedBtn').text('<?=get_texto_clave('Invitado')?>');
}
}
});
}
Wich seems to be working fine,
But I have just sent more than 500 invites to friends of mine, and they all got the 'ivited' class (When i completed the popup);
¿Did they all recived it?
I know the response debugging could be better, but still would like to know if user can send an invite to all of his friends same day no matter how many friends are. Or is there any user/app limitation?
Thanks
There is a no limit to the app requests you send
But if you use multi friend selector, you can select maximum of 50 and 25 in IE.
Naturally, if you're being spammy, you'll still get reported a lot and automated systems could block you, so remember to keep to a reasonable volume of requests.
Btw, You can read the response to know to whom it was delivered.
It used to be that the response from a request gave us an array of request ids (as described here http://developers.facebook.com/docs/reference/dialogs/requests/) but it seems now the response variable returns two items insead 'to' and 'request'. To being a comma delimited string of user ids and request being a request id. Is this correct? I have seen nothing about this anywhere but it is the behavior I am seeing currently.
Update
Here is a super simplified version of my call:
FB.ui({method: 'apprequests', message: 'My Great Request'}, requestCallback);
function requestCallback(response) {
for(var key in response){
console.log(key);
console.log(response[key]);
}
}
When I make a request to one person the variable response has two keys: request and to. Request is a request id, to is the id of the person I'm sending the request to. If I make a call to the graph api using the provided request id, however, I find that the user under both 'to' and 'from' are equal to the sender's name and fbid.
Alternatively, if I request to multiple people request is equal to a single request id and to is an array containing all the fbids of the users that had requests sent to them. When I make a call to the graph api, however, I once more find that both 'to' and 'from' contain the user id and name of the requesting user.
I faced similar issue yesterday. Had to fix my code. But today request_ids were back in the response. So I updated the code again. But this time to work with both type of objects.
I found the documentation here (move down to the "Performance improvements" section)
http://developers.facebook.com/blog/post/569/
But it still doesn't explains why they reverted the change today. Or was it accidently released yesterday.
As in the documentation, the new callback will receive an object (response) that contains an array (request_ids) of request ids:
{
"request_ids": [
0: [request_id]
1: [request_id]
...
]
}
So I suppose you can loop using this modified code:
function requestCallback(response) {
for( var k in response.request_ids ) {
console.log(k);
console.log(response.request_ids[k]);
}
}
There is already a bug filed here
http://developers.facebook.com/bugs/129565473812085
There is no clear information yet whether the response is really changed or its a bug.