Reputation: 125
I am developing a website in C#, using the Facebook API and getting logged in user's friend list. I bind this list in a Datalist with checkbox, friends picture, Name and UserID.
When I check some checkboxes and click on a button, I want to send some sort of invite to the checked friends. I want to send the invite via a private message, notification or any other solution (but not on the user's wall). Is this possible?
I have checked all posts ,which are already in Stackoverflow. And also checked this one http://www.fbrell.com/xfbml/fb:server-fbml-multi-friend-selector
Upvotes: 1
Views: 1262
Reputation: 125
This code will post on your friend's wall ,whatever you want to post:
for (Int32 i = 1; i < DLFbFriend.Items.Count; i++){
CheckBox Chkbox =(CheckBox)DLFbFriend.Items[i].FindControl("chkUserID");
if (Chkbox.Checked)
{
HiddenField hdfUserId = (HiddenField)DLFbFriend.Items[i].FindControl("hdfUserID");
string d = hdfUserId.Value;//friend's facebook generated id,whom you want to invite
String link = "what ever you want to post";
string url1 = "https://graph.facebook.com/" + d + "/feed?access_token=" + Request.QueryString["access_token"] + "&link=" + link + "&from=" + Session["Pinny_USER"].ToString().Split('~')[0] + "&name=Register with Pinny&message=Your friend invites you&picture=http://168.144.124.15/images/logoPinny.jpeg";
HttpWebRequest request1 = (HttpWebRequest)WebRequest.Create(url1);
request1.Method = "POST";
// execute the request
HttpWebResponse response1 = (HttpWebResponse)request1.GetResponse();
// we will read data via the response stream
System.IO.Stream ReceiveStream1 = response1.GetResponseStream();
StreamReader readStream1 = new StreamReader(ReceiveStream1);
string json1 = readStream1.ReadToEnd();
countinvited += 1;
}
}
Upvotes: 0
Reputation: 47956
What you are looking for is called "App-generated Requests"
. These are requests that are sent from inside your application without needing your users to see or act on the requests dialog.
The following code is taken from the Facebook documentation - https://developers.facebook.com/docs/channels/#requests
<?php
$app_id = YOUR_APP_ID;
$app_secret = YOUR_APP_SECRET;
$token_url = "https://graph.facebook.com/oauth/access_token?" .
"client_id=" . $app_id .
"&client_secret=" . $app_secret .
"&grant_type=client_credentials";
$app_access_token = file_get_contents($token_url);
$user_id = THE_CURRENT_USER_ID;
$apprequest_url ="https://graph.facebook.com/" .
$user_id .
"/apprequests?message='INSERT_UT8_STRING_MSG'" .
"&data='INSERT_STRING_DATA'&" .
$app_access_token . "&method=post";
$result = file_get_contents($apprequest_url);
echo("App Request sent?", $result);
?>
Once sent, new requests a user has received are visible as a counter on your application's bookmark and it also increments the counter next to the appropriate Dashboard.
The code is in PHP but it is using the very generic file_get_contents()
method. You can use this logic with any language capable of making HTTP requests.
Upvotes: 1