views:

2137

answers:

1

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

+3  A: 

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%>"/>
Zeus
how can i add these id's it is set in the page sourece and i will not know the user friends except from the code so h can i set these id's from code behind? i am using C# under asp.net 2008 and the multi-friend-selector is FBML tag not HTML tag that i can pass it attributes values from code behind how can i do that?
Ahmy
are you using a facebook .Net toolkit like http://www.codeplex.com/FacebookToolkit ?
Zeus
No i am not using it i need to set the Id's of users excluded from the multi-friend-selector
Ahmy
Are you accessing the facebook api from your code behind in c#?if so you can use the following api call to get the users' app using freinds: http://wiki.developers.facebook.com/index.php/Friends.getAppUsers
Zeus
edited my answer to show example in C# using aforementioned toolkit. although you're not using it, the example may be of use to you! (may be someone else will provide a different example)
Zeus
nothing new as i don't know how to supply the id's from code behind or is there any method to select friends who haven't used the application yet but this tags need to fill the attribute of id's and how can i do that ?
Ahmy
You can pass the ID's from the code behind to the FBML using a public string, and referencing it in your FBML like this <%=Public_String%> as shown in the example.On load this will bind the value of public_string from your code behind into your tag.or are you asking how to access the api from C# ?please edit your original question to make it clearer what you are asking...
Zeus
Mr.Zeus i have tried what u wrote and used silver tags to call puplic string but the page clashed when i use exclude_ids="<%=CURRENT_USER_FRIENDS%>" so how can i solve this bug? thanks for ur attention
Ahmy
I have traced the page and the problem from API.friends.getAppUsers(); and when i mended it by using fbservice and traced the ID returned i discovered that it returns ID's that is already online and logged in to the application not in general the ID's that use the application did u get what i mean ?
Ahmy
friends.getAppUsers() will only get the ID's of people who are using your app AND are a friend of the logged in user. These are the ID's you will want to Exclude in your friend selector. if you are having problems with the api itself, it might be worth asking in the facebook dev forums here: http://forum.developers.facebook.com/
Zeus
Ah! I think I understand... you can only get the ID's of users who have given your app permission. If you are allowing users to interact with your app without asking them to give your app permission, you can't get their ID's or profile details as far as I know. see http://www.facebook.com/help.php?page=887 and http://wiki.developers.facebook.com/index.php/Automatic_Authentication for info on Authorizing your users.
Zeus
You have to know that any user use my application should be authorized to use the application i did'nt configure it but this is already exist and when i use your code again and i have logged in with two different users in 2 different browsers it obtains users who is already signed in not users who used the application and i am clear in my describtion so don't say to me that friends.getAppUsers() gets users use application i haver tried it and nothing of ur claims occurrs
Ahmy
I merely quoted what the documentation for Friends.getAppUsers says. If you are experiencing otherwise it would be best to ask in the facebook developer forum. I think I have helped all I can here.
Zeus
Thanks for ur help i know that but i need any method u have tried and know it's results well and i am too thankfull to u for ur sharing me this problem but when i try it it returns to me users who are online now at facebook and use this application but may be there is a method that do that as many games do u can go to the application and see urself http://apps.facebook.com/hanggame/
Ahmy
Where are u Zeus? i am witting ur reply plz share me the problem
Ahmy

related questions