我正在尝试获取Facebook用户的userID,我已经具有access_token,并且使用http请求来执行此操作。我的简单问题是:我想要用户的ID,但是我的程序崩溃了...我使用WPF,C#这是我的小电话:
var url = string.Format("https://graph.facebook.com/me?access_token=" + token + "&response_type=id");
var req = WebRequest.Create(url);
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
string postData = "'access_token='" + token;
byte[] byteArray = Encoding.UTF8.GetBytes(postData);
var stream = req.GetRequestStream();
stream.Write(byteArray, 0, byteArray.Length);
stream.Close();
WebResponse response = req.GetResponse();
aTextBox.Text = ((HttpWebResponse)response).StatusDescription;
stream = response.GetResponseStream();
StreamReader reader = new StreamReader(stream);
谢谢!
最佳答案
不要为此使用Web浏览器!您可以将HttpWebRequest
用于此类情况:
string url = "https://graph.facebook.com/me?access_token=" + token + "&response_type=id";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
HttpWebResponse response = (HttpWebResponse)request.GetResponse ();
Stream receiveStream = response.GetResponseStream ();
StreamReader readStream = new StreamReader(receiveStream, Encoding.UTF8);
string responseData = readStream.ReadToEnd();
关于c# - 获取具有http请求C#WPF的Facebook用户的userID,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/9775871/