[英]Facebook integration for login
我在为我的网站集成Facebook时遇到问题。
这是代码:
private static string GetFacebookUserJSON(string access_token)
{
string url = string.Format(
"https://graph.facebook.com/me?access_token={0}&fields=email,name,first_name,last_name,link",
access_token);
WebClient wc = new WebClient();
Stream data = wc.OpenRead(url);
StreamReader reader = new StreamReader(data);
string s = reader.ReadToEnd();
data.Close();
reader.Close();
return s;
}
不幸的是,它给了我一个WebException was unhandled by user code
OpenRead()
行上的WebException was unhandled by user code
。 另外,我收到了来自联系服务器的(400) Bad Request
的信息。
我怎么解决这个问题?
使用它来检测确切的错误:
private static string GetFacebookUserJSON(string access_token)
{
try
{
string url = string.Format("https://graph.facebook.com/me?access_token={0}&fields=email,name,first_name,last_name,link", access_token);
WebClient wc = new WebClient();
Stream data = wc.OpenRead(url);
StreamReader reader = new StreamReader(data);
string s = reader.ReadToEnd();
data.Close();
reader.Close();
return s;
}
catch (WebException wex)
{
string pageContent = new StreamReader(wex.Response.GetResponseStream()).ReadToEnd().ToString();
return pageContent;
}
}
或者我建议使用Fiddler并使用日志中的响应更新您的问题
有看得更远这里大约Facebook登录证券的详细信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.