简体   繁体   中英

Getting profile picture of friends from facebook

Thats all I have tried.

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());
        }
    } 

It Gives me the friends name and id, but i need picture as well, the above query works fine on fb api graph explorer and gives the url of picture, but on unity it is not working. Please help if somebody can. Thanks

That's the way I get picture from a facebook userID in a coroutine :

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);

Then use your Texture2D where you want.

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

this line must be like this;

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM