I have a website that I registered as a facebook app. Now I have an application id.
My site is ASP.net C #. When a user clicks a button, I would like him to post a predefined message on the wall. I expect Facebook to present the user with a login dialog - they will log in and provide permission to publish for my web application.
Does anyone have sample code that would do this? I think I need to use the graphical API, but all the examples I've seen use PHP, which I know nothing about. I am looking for an example that will use Java Script (which I know almost nothing) or C # (beautiful!).
* Update *
I managed to get access_token. Now I am calling through the C # Facebook API to post it to the wall. I get an error message:
(# 803) Some of the aliases you requested do not exist: profile_id
I went through the api code and found that he was trying to send a message to the following address: { https://graph.facebook.com/PROFILE_ID/feed }, message data is: message = Example + message + from + c% 23 + sdk & access_token = 199209316768200 | 2.1avFTZuDGR4HJ7jPFeaO3Q __. 3600.1302897600.1-100000242760733 | R4DkNDf4JCb6B2F64n5TSQwBqvM
I am sure my token must be valid. Before requesting an access token, I requested publish_stream for an application authorization request as follows:
Response.Redirect ("https://www.facebook.com/dialog/oauth?client_id=" + myAppId + "&redirect_uri=" + myURL + "&scope=publish_stream");
The sdk code that actually makes the request looks like this:
private string MakeRequest(Uri url, HttpVerb httpVerb,
Dictionary<string, string> args)
{
if (args != null && args.Keys.Count > 0 && httpVerb == HttpVerb.GET)
{
url = new Uri(url.ToString() + EncodeDictionary(args, true));
}
HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
request.Method = httpVerb.ToString();
if (httpVerb == HttpVerb.POST)
{
string postData = EncodeDictionary(args, false);
ASCIIEncoding encoding = new ASCIIEncoding();
byte[] postDataBytes = encoding.GetBytes(postData);
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = postDataBytes.Length;
Stream requestStream = request.GetRequestStream();
requestStream.Write(postDataBytes, 0, postDataBytes.Length);
requestStream.Close();
}
try
{
using (HttpWebResponse response
= request.GetResponse() as HttpWebResponse)
{
StreamReader reader
= new StreamReader(response.GetResponseStream());
return reader.ReadToEnd();
}
}
- , ?
,
Rob.