Facebook API - How could I count invited friends by user of my app?
I know that it is possible, I saw it few months ago in one app. I would like to achieve condition: if user invited 3 or more friends then... - How I could check it?开发者_运维问答
How could I show how many users are checked to invite? (I would use multi-friend-selector
)
@Rin open up the friend selector box, then right click and inspect element. Select and deselect a friend, watch the code, there should be a class that changes the css, you could then use document.getElementsByClassName('selectedUser').length
Tell me if it doesn't work.
The invited friends come into an array which can be accessed like this:
if(isset($_POST["ids"]))
{
$count_invites = count($_POST["ids"]);
// insert $count_invites into database against current user
}
As the accepted answer don't give much information I decided to post mine too. According to request dialog docs, callback is called after user sends the requests using JavaScript SDK:
//open request dialog, specify the callback
FB.ui({method: 'apprequests',
message: 'My Great Request'}, requestCallback);
//callback
var requestCallback = function(response) {
alert("Invited " + response.to.length + " friends");
}
The Sarfasz's answer is refering to use of deprecated FBML fb:request-form. Documentation can be still found here, but developers should use JavaScript SDK instead.
To have better control over friends selection, custom request dialog can be implemented. The app would load friends using Graph API and then send request with specified "to" parameter:
//open request dialog, specify the callback
FB.ui({method: 'apprequests',
message: 'My Great Request',
to: '123456789,123456799,123456800,12345678999'}, requestCallback);
This will send the number of friends invited by get method on the callback URL:
function sendRequestViaMultiFriendSelector() {
FB.ui({method: 'apprequests',
message: 'yourmessage'
}, requestCallback);
}
function requestCallback(response)
{
if(response && response.request) {
location.href='callback.php?num_invited=' + response.to.length;
} else {
location.href='callback.php?num_invited=0';
}
}
精彩评论