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

Jas*_*tka 6 android unity-game-engine facebook-unity-sdk

我正试图通过以下方式获取游戏用户的个人资料照片 -

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;
        }
Run Code Online (Sandbox Code Playgroud)

但它没有用.我没有错.

No *_*ame 7

Jason Pietka的答案还可以,但有点旧.今天我们我们FB.API:

FB.API("me/picture?type=med", Facebook.HttpMethod.GET, GetPicture);
Run Code Online (Sandbox Code Playgroud)

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

}
Run Code Online (Sandbox Code Playgroud)


Jas*_*tka 6

我用这个修好了 -

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");
Run Code Online (Sandbox Code Playgroud)