【问题标题】:How to get facebook friends from facebook graph api in c#如何从 C# 中的 facebook graph api 获取 facebook 好友
【发布时间】:2014-07-17 06:41:06
【问题描述】:

我无法从 facebook graph api 获取好友列表。

Bad 请求抛出异常。

https://graph.facebook.com/me/friends?access_token="accessTokenString"; 这是我的代码

 public IDictionary<string, string> GetUserData(string accessCode, string redirectURI)
    {

        string token = GetHTML(Facebook_GraphAPI_Token + "client_id=" + AppID + "&redirect_uri=" + HttpUtility.HtmlEncode(redirectURI) + "%3F__provider__%3Dfacebook" + "&client_secret=" + AppSecret + "&code=" + accessCode);
        if (token == null || token == "")
        {
            return null;
        }


        string friendsData = Web.GetHTML(Facebook_GraphAPI_Friends + "fields=id,first_name,last_name,name,email,username,gender,link,bio,birthday,friendlists,friends&access_token=" + token.Substring("access_token=", "&"));
        //string substringToken=token.Substring("access_token=", "&");
        //string friendsData = Web.GetHTML(Facebook_GraphAPI_Friends + substringToken);


        return friendsData ;
    }





public static string GetHTML(string URL)
    {
        string connectionString = URL;

        try
        {
            System.Net.HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(connectionString);
            myRequest.Credentials = CredentialCache.DefaultCredentials;
            //// Get the response
            WebResponse webResponse = myRequest.GetResponse();
            Stream respStream = webResponse.GetResponseStream();
            ////
            StreamReader ioStream = new StreamReader(respStream);
            string pageContent = ioStream.ReadToEnd();
            //// Close streams
            ioStream.Close();
            respStream.Close();
            return pageContent;
        }
        catch (Exception)
        {
        }
        return null;
    }

【问题讨论】:

  • 显示重现此问题的代码
  • @Sayse 请看看我的代码块,我已经更新了它。请帮助我
  • 我不确定,但我想它是为 friendsData 完成的连接
  • @Sayse 它在 FriendsData 中返回 null 并且在异常中它显示错误请求

标签: c# javascript asp.net asp.net-mvc facebook-graph-api


【解决方案1】:

我在好友请求 api 中发现了错误的字段 朋友列表,朋友请删除这些字段

正确的终点 https://graph.facebook.com/me/friends?fields=id,first_name,last_name,name,email,username,gender,link,bio,birthday&access_token={您的 Facebook 访问令牌}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-25
    • 1970-01-01
    相关资源
    最近更新 更多