I am working with the Facebook Javascript SDK and I am trying to set up a rewards system for sending invites to Friends. Basically, I want to give the user points for simply sending invites to their friends using the friend invite dialog provided by the Facebook Javascript SDK. That said, I set everything up based on the Friend Smash tutorial on the FB developers website and I am creating a custom, multi-friend selector to send invites. The invite dialog comes up properly and the invite sends correctly.
The Javascript that sends the invite looks like this:
function sendRequest() {
// Get the list of selected friends
var sendUIDs = '';
var mfsForm = document.getElementById('mfsForm');
for(var i = 0; i < mfsForm.friends.length; i++) {
if(mfsForm.friends[i].checked) {
sendUIDs += mfsForm.friends[i].value + ',';
}
}
// Use FB.ui to send the Request(s)
FB.ui({method: 'apprequests',
to: sendUIDs,
title: 'Help me get some points!',
message: 'Help me get some points by coming over to XXX and registering to play!',
}, callback);
}
However the request's response object looks like this when sending to one friend:
{request: "412752342228182", to: Array[1]}
And it looks like this when inviting two friends:
{request: "414967121961627", to: Array[2]}
The object contains the "request" field which is the unique request ID for the invite, as expected. The Facebook documentation states I am supposed to get an array of user IDs of the recipients in the response object's "to" field but that strange Array[X] is there instead. Is this the correct response? Am I missing something?
Any help on this is appreciated. Thanks in advance for your time.
Nevermind, I figured it out. The Array[X] is more of a placeholder for the actual array so if you parse to[0] or to[1], you get the actual userids for those that you invited.
Related
I'm using the following Javascript for my users to send requests to "invitable friends" from my Facebook app:
FB.ui({
method: 'apprequests',
message: 'Come play with me etc.',
to: str_ids
},
requestCallback
);
function requestCallback(response){
if(response){
console.log(response);
}
else{
//show error to user
}
}
Where str_ids is a string containing the IDs returned by the invitable friends API. This all works fine.
When I invite a single user, let's say his Facebook ID is 1593894704165626, I get the following response:
request
"1399842883640198"
to
["1593894704165626"]
So here I have a unique request ID and the invited person's Facebook ID. I can now store this data in my database along with the inviter's ID, so I have all the necessary info.
However, now I want to reward the inviter after the invitee accepts the invitation and I'm running into a problem.
If user A and user B both invited user C, then when user C joins the game, how do I know whether to reward A or B?
I see from this question that it's possible to pass another parameter along with the invitation, which should help identify the inviter:
Facebook tracking who Invited whom
The first answer here suggests that you can pass such a custom parameter, but doesn't say how. Facebook's convoluted documentation is driving me insane.
Another thing - even if I send that additional parameter, I think there's a problem - for new users the app redirects to the Facebook page that checks whether they want to allow access to the app, and by the time they're redirected back to the app, the additional parameter will be lost.
Is there any solution to this?
The facebook docs here say "it is the Developers' responsibility to delete a Request once it has been accepted". As far as I understand, when someone sends a request to multiple users on facebook like this:
function sendRequestViaMultiFriendSelector() {
FB.ui({method: 'apprequests',
message: 'test message'
}, requestCallback);
}
only one request_id is returned via requestCallback() function.
Then, if I delete the request when someone accepts it, how would other users accept the deleted request?
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 delete the corresponding requests like below:
if(isset($_GET['request_ids']))
{
$request_ids = $_GET['request_ids'];
}
$request_ids = explode(",", $request_ids);
foreach($request_ids as $request_id)
{
$full_request_id = $request_id."_".$fbid; //$fbid is current user facebook id
$facebook->api("$full_request_id","DELETE");
}
Check out the Request ID Format section of the FB request overview page.
The actual graph path for a request actually sent to specific user is "request-id"_"recipient-user-id".
you can access to facebook on mobile mode (m.faceook.com)
1-access the invitation panel
2-display all the invitations
3-open console mode in chrome
4-activate jquery by cpying and pasting all the jquery.min code into console
and excecute this script :
$("._54k8._56bs._56bt").trigger("click");
that will cancel or the invitation sent
I need to keep a track of users referring other users to my website. So i want whenever a user invites his friends from facebook, the invitation link to contain his userid. Is it possible to send invites with random urls.
For eg : Right now the user gets the invitation link for http://example.com because that's what i have specified in my app site url.
I want the invitation link to be http://example.com?referrer=joe
I want the invitation link to be http://example.com?referrer=joe
And “joe” would be who or what here? If it’s the user sending the request – you have his id already, it’s in the request object details under from.
If you want to pass any other referential data – the Requests dialog has the data parameter for that. You can put any text data in there, up to 255 characters long. And when the user follows the request, you will get the request id[s] they are acting upon – and then you can read the request details from the API, and you will get that value you put into data back from there as well.
See docs: https://developers.facebook.com/docs/reference/dialogs/requests/ and https://developers.facebook.com/docs/requests/
Imagine, that you have JS function:
function invite(){
//number from 0 to 9
var i = Math.floor((Math.random()*10));
//get random param
var param = arrayOfDefinedParams[i];
//define request URL
var requestUrl = "https://www.facebook.com/dialog/apprequests?app_id=<APP_ID>&message=<YOUR_MESSAGE>&redirect_uri=<URL_SET_IN_APP_DASHBOARD>/?param="+param;
//show modal window with request URL and random param
myWindow=window.open(requestUrl,'','width=400,height=300');
myWindow.focus();
}
All you have to do now, is binding invite() to onclick event on any element ;)
I am developing an ASP.NET application. I implemented Facebook JavaScript API in my application, for connect with Facebook and get FB friend list of user. I had done this successfully.
Now, I want to count how many friends are invited by user. Is it possible with facebook API. User can select multiple friends and i want to count how many friends selected and invited by user, Invited friends Id is bonus if We can get.
Please don't forget that facebook changed its Oauth settings for security reasons.
I'm also trying to get ids values after Send Invitation button clicked and page post back to
if (Request.Form["ids"] != null)
{
span1.InnerHtml = "ids";
//put success code here..
}
else
{
span1.InnerHtml = "oops no id";
}
if (Page.PreviousPage != null)
{
span1.InnerHtml = "ids";
//put success code here..
}
else
{
span1.InnerHtml = "oops no id";
}
but in this case program control always goes to else condition it means after page is post back form return null value.
Is there any way to get ids of invited friends.
Thanks.
If you using Facebook Requests to send invites (you really should, it's intended for this), the only way to get invited friends is via Facebook Requests Dialog callback:
FB.ui({method: 'apprequests', message: 'Whoa!'}, callback);
function callback(response){
// response.to now contain array of invited users ids
console.log('Invited friends ids', response.to);
if (response.request) {
console.log('Efficient Request id', response.request);
} else {
console.log('Requests Ids', response.request_ids);
}
}
There is no way to get request sent by user via Graph API or FQL, you only can get requests received by user. You may save all requests sent by your users and rely on this data if you need aggregated count of invitation sent...
Ok finally I resolve this issue and get invited friends ids..
As we know we use javascript sdk for FB connect so my solution is in concern of Java script:
Just make on change in your .js file where you put your facebook connect javascript code. Use Get or Request Method instead of Post Method in fb:request-form tag.
<script type="text/javascript>
var fbhtml = "<fb:serverFbml width=\"" + width_of_invitation_div + "\">
<script type=\"text/fbml\"><fb:fbml><fb:request-form action=" + window.location + " method="REQUEST" invite="true" type="" + type_of_fb_request_form + "" hold=" /><br mode="></fb:request-form></fb:fbml></script></fb:serverfbml>"
</script>
After invitation send to users selected friends you get ids[] in url.
you can get these ids through query string and split ids by comma(,) and store in array.
Hope this will help for other devs.
I have a facebook application that is published at facebook platform and i used facebook API to invite friends and i have succeeded in creating invitation form but the problem is that when u invite friend and send invitation and the invitation request sent to the user and the user accept it this friend appears again in the friend list that can be invited again
For example :
i have friend in my friend list named X and when i send invitation to him the invitation is sent and and X accept the invitation and when i try to send invitation again the friend X appears again in the list that i can select from to send invitation this means that may i send an invitation to this user (X) and he is already playing the game i need to know how to fix this problem so friends appear in the friend list (for invitation )only friends that not use the application.
My application at the following link
My Game application
visit it and see the problem exactly after inviting friends they will appear again is this normal in any game application?
thanks in advance for any reply
In FBML if you are using the friend-selector you can pass it an array exclude_ids. If you use the api to find the users' friends who are already using your app, you can exclude them this way.
This also works in the multi-friend-selector which sits inside an fb:request-form tag.
EDIT: the array of users to exclude can be obtained through the api call Friends.getAppUsers.
Following example uses the .NET Facebook Developer Toolkit. (mainly because that's how I've done it before!)
CODE BEHIND:
public string CURRENT_USER_FRIENDS = "";
//Call this function on pageload or where you like
private void PopulateFriendsData()
{
//exclude friends who already have the app from the inviter
string UsersToExclude = string.Empty;
IList<long> AppUserFriends = this.Master.API.friends.getAppUsers();
foreach (long L in AppUserFriends)
{
UsersToExclude += L.ToString() + ",";
}
CURRENT_USER_FRIENDS = UsersToExclude.TrimEnd(',');
}
PAGE:
<fb:multi-friend-selector
actiontext="Select the friends you want to invite"
rows="3"
exclude_ids="<%=CURRENT_USER_FRIENDS%>"/>