In Facebook Send friend request with out fbml tag

Aug 20, 2009 at 9:16 AM

Hi

I am working in facebook application  i want to send friend invitation with out using FBML tags

I am developing facebook application using asp.net

plz help any one

Thnaks ...

 

Aug 21, 2009 at 8:23 AM
Edited Aug 21, 2009 at 8:25 AM

This is how I do it (found here http://www.richardmaxwell.name/Blog/Blog150.aspx) :

 

        public void MultiFriendSelector()
{
//init multi_friend_selector parameters

var API_KEY = ConfigurationManager.AppSettings["APIKey"];
var SECRET = ConfigurationManager.AppSettings["Secret"];
const string ACTION = "http://apps.facebook.com/yourapp/";
const string ACTION_TEXT = "Invite friends to yourapp";
const string CONTENT = "Hey, come use yourapp <fb:req-choice url=\"http://apps.facebook.com/yourapp/\" label=\"Acccept\" />" ;

const string MAX = "20";
const string INVITE = "true";
const string TYPE = "yourapp";

var strExcludeIds = GetAppUsers();
var strConcat = String.Format("action={0}actiontext={1}api_key={2}content={3}exclude_ids={4}invite={5}max={6}type={7}{8}",
ACTION, ACTION_TEXT, API_KEY, CONTENT, strExcludeIds, INVITE, MAX, TYPE, SECRET);
var strSig = GetMD5Hash(strConcat);

Response.Write("<form id=postForm target=_top action=http://www.facebook.com/multi_friend_selector.php method=post>");

Response.Write("</form>");

var sb = new StringBuilder();

sb.Append("<script language=javascript>");
sb.Append("function setElem(form, name, value) {");
sb.Append("var el = document.createElement(\"input\");");
sb.Append("el.type = 'hidden';");
sb.Append("el.name = name;");
sb.Append("el.value = value;");
sb.Append("form.appendChild(el);");
sb.Append("}");

sb.Append("var myForm = document.forms['postForm'];");
sb.Append("setElem(myForm, 'action', '" + ACTION + "');");
sb.Append("setElem(myForm, 'actiontext', '" + ACTION_TEXT + "');");
sb.Append("setElem(myForm, 'api_key', '" + API_KEY + "');");
sb.Append("setElem(myForm, 'content', '" + CONTENT + "');");
sb.Append("setElem(myForm, 'exclude_ids', '" + strExcludeIds + "');");
sb.Append("setElem(myForm, 'invite', '" + INVITE + "');");
sb.Append("setElem(myForm, 'max', '" + MAX + "');");
sb.Append("setElem(myForm, 'type', '" + TYPE + "');");
sb.Append("setElem(myForm, 'sig', '" + strSig + "');");
sb.Append("myForm.submit();");
sb.Append("</script>");
ClientScript.RegisterClientScriptBlock(typeof(String), "addScript", sb.ToString());
}

private static string GetMD5Hash(string input)
{
var md5Hasher = MD5.Create();

var data = md5Hasher.ComputeHash(Encoding.Default.GetBytes(input));

var sb = new StringBuilder();

for (var i = 0; i < data.Length; i++)
{
sb.Append(data[i].ToString("x2"));
}
return sb.ToString();
}

private string GetAppUsers()
{

var appUsers = Master.API.friends.getAppUsers();
var sb = new StringBuilder();
foreach (var friend in appUsers)
{
sb.Append(friend + ",");
}
if (sb.Length > 0) sb.Remove(sb.Length - 1, 1);
return sb.ToString();
}
}
}


I have a hyperlink which links to an invites page, the aspx page is blank, with only this in code behind.

 

Mar 19, 2010 at 11:05 AM

Hi,

This code is  not working in canvas fbml applicatton..