How can i get the multiple(friends) facebook profile image using www or any other method

0 votes
Currently I am accessing  the data top 10 ranker of facebook. But in the callback i am not able to get the profile image of the all 10 ranker.
here is the code  in the call back of function gettopnrankersfromfacebook,
 
 
public class UnityCallBackUserId :MonoBehaviour, App42CallBack  
{  
 
List<string> fbplayer=new List<string>();
public void OnSuccess(object response)  
WWW www;
 
Game game = (Game) response;       
Debug.Log("gameName is " + game.GetName());   
Debug.Log ("scorelist"+game.GetScoreList().Count);
foreach(Transform child in FindRankOnGameOver.instance.scroolview.transform)
{
GameObject.Destroy(child.gameObject);
}
for(int i = 0;i < game.GetScoreList().Count; i++)  
{
fbplayer.Add(game.GetScoreList()[i].GetUserName());
// Debug.Log("userName is : " + game.GetScoreList()[i].GetUserName());   
Debug.Log("userName is : " + game.GetScoreList()[i].GetUserName());  
Debug.Log("score value is : " + game.GetScoreList()[i].GetValue());  
Debug.Log("scoreId is : " + game.GetScoreList()[i].GetScoreId());  
Debug.Log("Created On : " + game.GetScoreList()[i].GetCreatedOn());  
Debug.Log("Facebook id is : " + game.GetScoreList()[i].GetFacebookProfile().GetId());  
Debug.Log("Facebook name is : " + game.GetScoreList()[i].GetFacebookProfile().GetName());  
Debug.Log("Facebook picture is : " + game.GetScoreList()[i].GetFacebookProfile().GetPicture());
 
 
GameObject friendsentry;
friendsentry=Instantiate(FindRankOnGameOver.instance.friends)as GameObject;
friendsentry.transform.parent=FindRankOnGameOver.instance.scroolview.transform;
 
Transform picture=friendsentry.transform.Find("Image");
Image fbpic=picture.GetComponent<Image>();
www = new WWW(game.GetScoreList()[i].GetFacebookProfile().GetPicture());
fbpic.sprite=Sprite.Create(www.texture,new Rect(0,0,128,128),new Vector2(0,0));
 
 
 
Transform name=friendsentry.transform.Find("Name");
Transform score=friendsentry.transform.Find("Score");
Text fbname=name.GetComponent<Text>();
Text gamescore=score.GetComponent<Text>();
fbname.text=game.GetScoreList()[i].GetFacebookProfile().GetName();
gamescore.text=game.GetScoreList()[i].GetValue().ToString();
 
 
 
FindRankOnGameOver.instance.scrolpanel.SetActive(true);
 
 
 
 
 
 
}  
 
 
public void OnException(Exception e)  
{  
//Enable all the colliders
Debug.Log("Exception : " + e);  
}  
 
}
 
i am getting all the things except profile image. i am getting the error like image cannot downloaded yet or downloading is not completed yet but to trying to acess it. it tryed to use coroutines but i dont know how to use in for loop. please help me in that i never used www.
asked Jul 9, 2015 in App42 Cloud API-BaaS by Sourav Mishra (10 points)

1 Answer

0 votes

Hi Sourav,

Unity  follows some structure to download image from webUrl in a sprite texture.So whenever you want to download image from web you should use yield return statement like :

WWW www = new WWW(game.GetScoreList()[i].GetFacebookProfile().GetPicture());

yield return www;

For more information you can go through with this Unity Answer.

Let me know if it helps.

Thanks

Vishnu Garg


answered Jul 10, 2015 by Vishnu Garg (674 points)
hi vishnu ,
 
to use yield statement i have to use coroutines. is used it but i got error. so please let me know Can coroutines be used in external C# dlls? if possible then how
my error is  Exception : com.shephertz.app42.paas.sdk.csharp.App42Exception: System.NullReferenceException:
  at (wrapper managed-to-native) UnityEngine.MonoBehaviour:StartCoroutine_Auto (System.Collections.IEnumerator)


my code is
public class UnityCallBackUserId :MonoBehaviour, App42CallBack  
{  
   
    List<string> fbplayer=new List<string>();
    public void OnSuccess(object response)  
    {     Debug.LogError("profileimage OnSuccess");
        StartCoroutine(profileimage (response));
        }
        
        IEnumerator profileimage(object response)
    {
        Debug.LogError("profileimage");

        Game game = (Game) response;       
        Debug.Log("gameName is " + game.GetName());   
        Debug.Log ("scorelist"+game.GetScoreList().Count);
        foreach(Transform child in FindRankOnGameOver.instance.scroolview.transform)
        {
            GameObject.Destroy(child.gameObject);
        }
        WWW www;
        for(int i = 0;i < game.GetScoreList().Count; i++)  
        {
            fbplayer.Add(game.GetScoreList()[i].GetUserName());
            //            Debug.Log("userName is : " + game.GetScoreList()[i].GetUserName());   
            Debug.Log("userName is : " + game.GetScoreList()[i].GetUserName());  
            Debug.Log("score value is : " + game.GetScoreList()[i].GetValue());  
            Debug.Log("scoreId is : " + game.GetScoreList()[i].GetScoreId());  
            Debug.Log("Created On : " + game.GetScoreList()[i].GetCreatedOn());  
            Debug.Log("Facebook id is : " + game.GetScoreList()[i].GetFacebookProfile().GetId());  
            Debug.Log("Facebook name is : " + game.GetScoreList()[i].GetFacebookProfile().GetName());  
            Debug.Log("Facebook picture is : " + game.GetScoreList()[i].GetFacebookProfile().GetPicture());
           
           
            GameObject friendsentry;
            friendsentry=Instantiate(FindRankOnGameOver.instance.friends)as GameObject;
            friendsentry.transform.parent=FindRankOnGameOver.instance.scroolview.transform;
           
            Transform picture=friendsentry.transform.Find("Image");
            Image fbpic=picture.GetComponent<Image>();
           
            www = new WWW(game.GetScoreList()[i].GetFacebookProfile().GetPicture());
            yield return www;
            fbpic.sprite=Sprite.Create(www.texture,new Rect(0,0,128,128),new Vector2(0,0));
           
           
           
            Transform name=friendsentry.transform.Find("Name");
            Transform score=friendsentry.transform.Find("Score");
            Text fbname=name.GetComponent<Text>();
            Text gamescore=score.GetComponent<Text>();
            fbname.text=game.GetScoreList()[i].GetFacebookProfile().GetName();
            gamescore.text=game.GetScoreList()[i].GetValue().ToString();
           
           
           
            FindRankOnGameOver.instance.scrolpanel.SetActive(true);
           
        }
    }

but i got the exception;
please help me. if there is other way of doing this then also let me know

thanks
hi vishnu,
thaks for your response.
i already checked this link (http://answers.unity3d.com/questions/176372/can-coroutines-be-used-in-external-c-dlls.html) but i am not able to solved my  problem. what i have done i created a different script for callback and in the awake function i wrote this
unitycallback api=gameobject.getcomponent<unitycallback>();
and in success i wrote
api.startcoroutines(response);
but this not solved my problem but it increased my getting closed all the time.
please tell me some thing else.
if  i'm doing something wrong then please tell me how to do this
thanks
Download Widgets
Welcome to ShepHertz Product line forum, where you can ask questions and receive answers from the community. You can also reach out to us on support@shephertz.com
...