简体   繁体   English

Facebook集成登录

[英]Facebook integration for login

I am having trouble with integration with Facebook for my site. 我在为我的网站集成Facebook时遇到问题。

Here is the code: 这是代码:

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;
}

Unfortunately, it gives me a WebException was unhandled by user code on the OpenRead() line. 不幸的是,它给了我一个WebException was unhandled by user code OpenRead()行上的WebException was unhandled by user code Additionally, I have the information that I got a (400) Bad Request from the contacted server. 另外,我收到了来自联系服务器的(400) Bad Request的信息。

How can I solve this? 我怎么解决这个问题?

Use this to detect the exact error: 使用它来检测确切的错误:

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;
    }
}

Or I would suggest using Fiddler and updating your question with the response from it's log 或者我建议使用Fiddler并使用日志中的响应更新您的问题

Have a further look here for more information about Facebook login securities. 有看得更远这里大约Facebook登录证券的详细信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM