如何使用Facebook的Unity SDK获取用户的个人资料图片?

2023-12-29

我正在尝试使用此方法获取游戏用户的个人资料图片-

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

但它不起作用。我没有收到任何错误。


Jason Pietka 的答案很好,但有点旧。 今天我们我们FB.API:

FB.API("me/picture?type=med", Facebook.HttpMethod.GET, GetPicture);

GetPicture是一个回调方法,所以:

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

}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何使用Facebook的Unity SDK获取用户的个人资料图片? 的相关文章

随机推荐