多数民众赞成我尝试过的。
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图形资源管理器上运行正常,并给出了图片的网址,但在统一上它不起作用。如果有人可以,请帮助。感谢
答案 0 :(得分:1)
这就是我从协程中的facebook userID获取图片的方式:
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。
答案 1 :(得分:0)
字典pic = pictureData [&#34; data&#34;] as Dictionary;
这一行必须是这样的;
Dictionary pic = Facebook.MiniJSON.Json.Deserialize(friendData [&#34; data&#34;]。ToString())as Dictionary;