Facebook integration for login

I am having problems with Facebook integration for my site.

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 WebException was unhandled by user code

an inline OpenRead()

. Also, I have information about what I got (400) Bad Request

from the linked server.

How can I solve this?

+3


source to share


1 answer


Use this to spot 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 update your question with the answer from it log

Look else here for more information on Facebook Securities.

+2


source







All Articles