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.
The Facebook SDK for Unity complements Unity Technologies' cross-platform support, providing a pure-Unity write-once, run-everywhere experience across the key gaming platforms of WebGL, Unity Web Player, Android and iOS.
Jason Pietka's answer is OK but a bit old.
Today we us FB.API
:
FB.API("me/picture?type=med", Facebook.HttpMethod.GET, GetPicture);
GetPicture
is a callback method so:
private void GetPicture(FBResult result)
{
if (result.Error == null)
{
Image img = UIFBProfilePic.GetComponent<Image>();
img.sprite = Sprite.Create(result.Texture, new Rect(0,0, 128, 128), new Vector2());
}
}
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");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With