//这是我的代码。我在asp.net C#页面上写过。请检查一下,并告诉我哪里出错......以及为什么它不起作用????
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;
using System.IO;
using System.Text;
using System.Security.Cryptography;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
updatefbstatus();
Label1.Text = "You have successfully updated your status";
}
public void updatefbstatus()
{
string app_id = "4674344535438035667565358488";
string app_secret = "336851d2c3fhg7675g45ts2b89c46e58aa287fbf6kjiu766771f";
string scope = "publish_stream,manage_pages";
string status = "hello billu";
if (Request["code"] == null)
{
Response.Redirect(string.Format(
"https://graph.facebook.com/oauth/authorize?client_id={0}&redirect_uri=
{1}&scope={2}",
app_id, Request.Url.AbsoluteUri, scope));
}
else
{
Dictionary<string, string> tokens = new Dictionary<string, string>();
string url = string.Format("https://graph.facebook.com/oauth/access_token?
client_id={0}&redirect_uri={1}&scope={2}&code={3}&client_secret={4}&status=
{5}",
app_id, Request.Url.AbsoluteUri, scope, Request["code"].ToString(),
app_secret, status);
tokens.Add("message", status);
var auth = Uri.EscapeDataString(url) + Uri.EscapeDataString(status);
var postBody = "status=" + Uri.EscapeDataString(status);
HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
request.Headers.Add("Authorization", auth);
request.Method = "POST";
request.ContentType = "application/json";
using (Stream stream = request.GetRequestStream())
{
byte[] content = ASCIIEncoding.ASCII.GetBytes(postBody);
stream.Write(content, 0, content.Length);
}
WebResponse rsp = request.GetResponse() as HttpWebResponse;
Stream dataStream = rsp.GetResponseStream();
StreamReader reader = new StreamReader(dataStream);
string responseFromServer = reader.ReadToEnd();
}
}
}