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

Unity 5.1.1f1 Facebook SDK 6.2.2 Error 400: Bad request on getting player picture on iOS


I got stuck at getting profile picture on iOS devices. It works well on Editor, Android devices, even Facebook graph. After FB.init() called successfully, i call

string url = Util.GetPictureURL(fID, 128, 128);
FB.API(url, Facebook.HttpMethod.GET, AvatarAPICallback);

Following is the url after debugged:

v2.5/626213070847481/picture?g&width=128&height=128&redirect=false

on iPhone, it returns error 400: bad request.

Any answer is appreciated! Thanks


Solution

  • Get the UserID and use WWW to request a user picture.

    Example to download a sprite:

    private IEnumerator DownloadPicture(string userID){
        WWW www= new WWW("http://graph.facebook.com/"+userID+"/picture?width=200&height=200");
        yield return www;
    
        if(www.error==null)
            userPicture = Sprite.Create ((www.texture as Texture2D), new Rect (new Vector2 (0, 0), new Vector2 (www.texture.width, www.texture.height)), new Vector2 (0.5f, 0.5f));
        else
            userPicture = defaultPicture;
    }