How to get ids of facebook invited friends by user in my asp.net4.0 web application - facebook

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.

Related

Parsing the response object from sending a Facebook Invite Friend Request

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.

How to reward members for having their invites accepted in Facebook canvas app?

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?

deleting facebook requests

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

Facebook status update with PHP

My requirement was to update members status from my site, i am also thinking about displaying their friends photos and their last status update.
I have looked all over the docs and cant decide which works for my need. RESTful API, JavaScript API, FQL, XFBML, FBML, FBJS ?? whcin one works best? or best way?
It should be like, when they first go to the page,there will be nothing but a login option. when they click on it, a pop up should appear and when they are authorized, we display a text area to post update. Here, i wanted to show their friends pics too
when they came back later, they should able to post right away, must not ask for login again.
Can some one help me with the code?? I dont expect you to write everything, get the friends pic and their last update into a PHP array would be nice.
Many thanks
If u need to update users data stored at ur database so u will use the facebook API to check user signed in and get his data. i have an ifram application at facebook and i am using C# code (asp.net application) and when the user request the application i authenticate that he is signed in to facebook and check if he is already exist in my database? if not so i get his information(by using facebook API) and add the user in my data base and each time he visits the application i update his information.
With respect to his friends i get all facebook ids of the user friends and then loop these IDs and get the pic of each ID.
Download Facebook Developer Toolkit that enables u communicate with facebook and use facebook API to get user information.
hope that is will help u
Visit my application in facebook and u will see these features at the following link :
http://apps.facebook.com/hanggame/
Getting the session Key :
protected void Page_Load(object sender, EventArgs e)
{
//Facebook code for integration with facebook users:
_fbService.ApplicationKey = "Application Key";
_fbService.Secret = "Secret Key";
_fbService.IsDesktopApplication = false;
string sessionKey = (string)Session["Facebook_session_key"];
if (Session["Facebook_userId"] != null)
userId = (long)Session["Facebook_userId"];
// When the user uses the Facebook login page, the redirect back here will will have the auth_token in the query params
string authToken = Request.QueryString["auth_token"];
if (!String.IsNullOrEmpty(sessionKey))
{
_fbService.SessionKey = sessionKey;
_fbService.uid = userId;
}
else if (!String.IsNullOrEmpty(authToken))
{
_fbService.CreateSession(authToken);
Session["Facebook_session_key"] = _fbService.SessionKey;
Session["Facebook_userId"] = _fbService.uid;
Session["Facebook_session_expires"] = _fbService.SessionExpires;
}
else
{
Response.Redirect(#"http://www.Facebook.com/login.php?api_key=" + _fbService.ApplicationKey + #"&v=1.0");
}
userId = _fbService.uid;
//End of Facebook code
}

Inviting friends in facebook application

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%>"/>