Search code examples
androidunity-game-enginefacebook-unity-sdk

How to get user's profile picture with Facebook's Unity SDK?


I'm trying to get the profile pic of the user of the game using this-

void MyPictureCallback(FBResult result) // store user profile pic
{
        if (FB.IsLoggedIn)
        {
            WWW url = new WWW("http" + "://graph.facebook.com/" + FB.UserId + "/picture");

            Texture2D textFb2 = new Texture2D(128, 128, TextureFormat.ARGB32, false); //TextureFormat must be DXT5

            url.LoadImageIntoTexture(textFb2);
            profilePic.renderer.material.mainTexture = textFb2;
        }

But it isn't working. I am getting no errors.


Solution

  • I fixed it with this-

    WWW url = new WWW("https" + "://graph.facebook.com/" + userId + "/picture?type=large"); //+ "?access_token=" + FB.AccessToken);
    
                Texture2D textFb2 = new Texture2D(128, 128, TextureFormat.DXT1, false); //TextureFormat must be DXT5
    
                yield return url;
                profilePic.renderer.material.mainTexture = textFb2;
                url.LoadImageIntoTexture(textFb2);
                Debug.Log("Working");