【问题标题】:Getting profile picture of friends from facebook从 Facebook 获取朋友的个人资料图片
【发布时间】:2014-05-08 10:35:36
【问题描述】:

这就是我所尝试的。

void APICallback(FBResult result)                                                                                              
    {                                                                                                                              
        Debug.Log("APICallback");                                                                                                
        if (result.Error != null)                                                                                                  
        {                                                                                                                          
            Debug.LogError(result.Error);                                                                                                                                                                                         
            FB.API("/me?fields=id,first_name,friends.limit(100).fields(first_name,picture)", Facebook.HttpMethod.GET, APICallback);     
            return;                                                                                                                
        }                                                                                              
        profile = Util.DeserializeJSONProfile(result.Text);                                                                        
        Name = profile["first_name"];
        friends = Util.DeserializeJSONFriends(result.Text);
        Debug.Log (Name);
        foreach (object friend in friends) {
            Dictionary<string, object> friendData = friend as Dictionary<string, object>;
            foreach(KeyValuePair<string, object> keyval in friendData)
            {
                Debug.Log(keyval.Key + " : " + keyval.Value.ToString());
            }
            Dictionary<string, object> pictureData = Facebook.MiniJSON.Json.Deserialize(friendData["picture"].ToString()) as Dictionary<string, object>;
            Dictionary<string, object> pic = pictureData["data"] as Dictionary<string, object>;
            Debug.Log(pic["url"].ToString());
        }
    } 

它给了我朋友的名字和 id,但我也需要图片,上面的查询在 fb api 图形浏览器上运行良好,并给出了图片的 url,但在统一时它不起作用。如果有人可以请帮助。谢谢

【问题讨论】:

  • 你能在问题中包含你得到的确切结果吗?
  • Debug.Log(keyval.Key + " : " + keyval.Value.ToString());这给了我 id: 786453, name: Rehman 我也需要图片。
  • 但这只是您处理结果的方法。你首先在哪里发送请求?可能你只是在这里修改了请求,在哪里重复,每次发送第一个请求时忘记包含图片参数?

标签: c# facebook facebook-graph-api unity3d


【解决方案1】:

这就是我在协程中从 facebook 用户 ID 获取图片的方式:

WWW url = new WWW("https" + "://graph.facebook.com/" + userID + "/picture?width=64&height=64"); 

Texture2D textFb = new Texture2D(64, 64, TextureFormat.DXT1, false);

yield return url;
url.LoadImageIntoTexture(textFb);

然后在你想要的地方使用你的 Texture2D。

【讨论】:

    【解决方案2】:

    字典 pic = pictureData["data"] as Dictionary;

    这一行一定是这样的;

    Dictionary pic = Facebook.MiniJSON.Json.Deserialize(friendData["data"].ToString()) as Dictionary;

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-06-21
      • 2011-10-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-06-24
      • 1970-01-01
      相关资源
      最近更新 更多