allrounder
allrounder

Reputation: 49

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

Upvotes: 1

Views: 1942

Answers (2)

atromgame
atromgame

Reputation: 442

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

this line must be like this;

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

Upvotes: 0

Yannick
Yannick

Reputation: 21

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.

Upvotes: 1

Related Questions