簡體   English   中英

Facebook集成登錄

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM