some how i was getting result.Texture was always null..
so i have used the code from https://github.com/fbsamples/friendsmash-unity
even this code have some problems if you compile directly..
LoadPictureAPI(Util.GetPictureURL("me", 100, 100),MyPictureCallback);
delegate void LoadPictureCallback (Texture texture);
IEnumerator LoadPictureEnumerator(string url, LoadPictureCallback callback)
{
WWW www = new WWW(url);
yield return www;
callback(www.texture);
}
void LoadPictureAPI (string url, LoadPictureCallback callback)
{
FB.API(url,Facebook.HttpMethod.GET,result =>
{
if (result.Error != null)
{
Util.LogError(result.Error);
return;
}
var imageUrl = Util.DeserializePictureURLString(result.Text);
StartCoroutine(LoadPictureEnumerator(imageUrl,callback));
});
}
void LoadPictureURL (string url, LoadPictureCallback callback)
{
StartCoroutine(LoadPictureEnumerator(url,callback));
}
void MyPictureCallback(Texture texture)
{
Util.Log("MyPictureCallback");
Image im = GetComponent <Image>();
if (texture == null)
{
LoadPictureAPI(Util.GetPictureURL("me", 100, 100),MyPictureCallback);
return;
}
Vector2 v = new Vector2 (0, 0);
Rect r = new Rect (0f,0f,100f,100f);
im.sprite = Sprite.Create((Texture2D)texture, r, v);
}