Search Unity

How i can get all facebook user picture?

Discussion in 'Scripting' started by LAFI, Jun 15, 2015.

  1. LAFI

    LAFI

    Joined:
    Sep 5, 2014
    Posts:
    47
    Hi, I want to get all photos, facebook user and display them by allowing him to choose one of these images ?? how i can GET them?? How can i dispaly them??

    please i need Help!!!

    Thank you
     
  2. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,531
    Well for getting at the data requires the user to allow you access to their facebook account. You can learn all about that through the facebook api:
    https://developers.facebook.com/

    When integrating with the api you're just using basic C#/.net/mono. This means you can just google for .net tutorials for assistance in doing that. There's nothing special about unity for all this.

    Where the special comes in is once you've downloaded said images, is turning them into textures/sprites to put in the scene.

    You can use WWW.LoadImageIntoTexture once you have the url of the image through the facebook api.
    http://docs.unity3d.com/ScriptReference/WWW.LoadImageIntoTexture.html
     
    LAFI and Kiwasi like this.
  3. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    The Facebook API is pretty messy. It's poorly documented, and a pain to work with.

    From memory the process goes something like this
    • Initialise Facebook and log the player in
    • Use FB.API with a GET request to the appropriate graph location to get a list of the users friends. Note you will need the appropriate permission to access this. Check out the graph explorer to figures out which node you want to query.
    • Deconstruct the returned JSON to get an array of strings with the friends name.
    • Build the string for the picture URL
    • Use WWW to download the picture as a texture
    • Make a new sprite from the texture
    • Display the sprite
    Simple really. You'd think that a task as common as getting friends pictures would be done natively by the SDK. But Facebook doesn't care much about developers. So they don't bother to make anything straight forward or simple.
     
    JoRouss, LAFI and lordofduct like this.
  4. bart_the_13th

    bart_the_13th

    Joined:
    Jan 16, 2012
    Posts:
    498
    I think you can query the friendlist by using FB.API()
    Code (csharp):
    1.  
    2. FB.API("/me/friends");
    3.  
    and get the friend list in callback result. Usually you'll have an array of user_id in the "friends" field.
    Then you have to get the pictures by using the WWW with the data profided in the /(user_id)/picture


    It's complicated using Facebook API/SDK, I know, plus it always get updated(read:getting more and more complicated) regularly..

    [EDIT]
    But actually, if you really just want to send them request to play some apps or just send them message, maybe you can use FB.AppRequest
     
    LAFI and Kiwasi like this.
  5. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,531
    I've never actually programmed against the FB api... but this doesn't surprise me.

    At all.

    That website is so poorly programmed in all aspects.
     
    LAFI likes this.
  6. LAFI

    LAFI

    Joined:
    Sep 5, 2014
    Posts:
    47
    i just want to get all pictures for each user ( not just a profile picture)
     
  7. LAFI

    LAFI

    Joined:
    Sep 5, 2014
    Posts:
    47
    Thank you for your reply
    please can you give me an exemple to put me in the right way!!
     
  8. LAFI

    LAFI

    Joined:
    Sep 5, 2014
    Posts:
    47
    i need to show them in in a user interface
    how i van do that??
     
  9. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,531
    See this is all multiple step things.

    You say "I want to make a sandwich"

    I say, "First you need to get the ingredients: cold cuts, cheese, veggies, bread. Next you order them on one another. Cut in half and serve."

    You: "Yes, but can you put one together for me so I can has? I mean uh, to have as an example?"

    You: "Oh, and I forgot, I want that sandwich to be served with some coleslaw as well. Can you make that as well?"



    ...

    You display those facebook images in a user interface in the same way you'd display ANY image in a user interface.

    These are all separate tasks. I gave you direction in each separate task. Because together it's a large task. The best way to conquer large tasks is to break them down into their smaller parts and conquer them one by one.

    Try to create an user interface with images in your system. If you have specific problems with doing it, come ask us.

    Try to load images from the internet and put those in your user interface from previous step, if you have problems with that, let us know.

    Try to integrate with the Facebook API, and loading an image from there instead of like previous step, and again stick that in said user interface.

    You want an example of any of these? Like say the facebook API one? One that has TONS of examples on the internet already made up so that I don't have to wrestle with the facebook API at your behest... wasting my time so you could just copy past the code. Sorry, no, teach a man to fish, don't give a man a fish. Anyways... google to the rescue!

    googling "C# facebook api get profile picture"
    https://www.google.com/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=C# facebook api get profile picture

    FIRST result:
    http://stackoverflow.com/questions/...ture-using-facebook-c-sharp-sdk-from-codeplex

    Again... break things down into its parts, research those parts, then reconstruct into the whole. If you have trouble along the way, we're more than happy to help! But if you don't even put in this much effort... well I can't help you then.
     
  10. wasifmac

    wasifmac

    Joined:
    Feb 4, 2017
    Posts:
    4
    public void ShowAllMyFriends()
    {
    FB.API ("/me/invitable_friends?limit=400", HttpMethod.GET, CreateShowAllFriend);
    }

    void CreateShowAllFriend(IResult result)
    {
    IDictionary<string,object> data = result.ResultDictionary;
    List<object> friends = (List<object>)data ["data"];
    Dictionary<string,object> dictio = new Dictionary<string, object> ();
    frname= new List<string>() ;
    string name1 = string.Empty;
    string url = string.Empty;
    string frnfid = string.Empty;
    foreach (object obj in friends) {
    dictio = (Dictionary<string,object>)obj;
    IDictionary<string,object> innerDict = (Dictionary<string,object>)dictio ["picture"];
    IDictionary<string,object> secondInner = (Dictionary<string,object>)innerDict ["data"];
    name1 = dictio ["name"].ToString ();
    url = secondInner ["url"].ToString ();
    frnfid = dictio ["id"].ToString ();
    StartCoroutine (getFriendPicture (url,name1,frnfid));
    }
    }

    IEnumerator getFriendPicture(string urlp,string name2,string fid){
    WWW url1 = new WWW(urlp);
    yield return url1;
    Texture2D textFb2 = url1.texture;
    frurl.Add (url1);
    texTuure.Add (textFb2);
    frname.Add(name2);
    freid.Add (fid);
    if (texTuure.Count == 400) {
    printfriendList (index);
    }
    }

    void printfriendList(int ind)
    {
    for (int i =0; i < 6 ; i++)
    {
    Debug.Log (frname );
    txt .text = frname [ind].ToString();
    img .sprite = Sprite.Create (texTuure [ind], new Rect (0, 0, 50, 50), new Vector2 ());
    Debug.Log (freid [ind]);
    string temp=freid [ind];
    tog .onValueChanged.AddListener ((value) => showtoggleid (temp));
    ind++;
    }
    }
    #endregion
     
  11. Saddamjit_Singh

    Saddamjit_Singh

    Joined:
    Dec 4, 2015
    Posts:
    22
    Do anyone know how to create Open graph object in facebook via unity to send and ask for lives?
     
  12. tej_greykernel

    tej_greykernel

    Joined:
    Jul 15, 2017
    Posts:
    1
    If you have Facebook id of any user then you can use this method:

    private IEnumerator LoadProfile(string facebookId)
    {
    // Getting Facebook Profile
    string imageUrl = "http://graph.facebook.com/" + facebookId + "/picture?type=square&width=300&height=300";
    WWW www = new WWW(imageUrl);
    while (!www.isDone)
    {
    yield return null;
    }
    string path = Application.persistentDataPath + "/Profiles/FacebookImage.png";
    if (File.Exists(path))
    {
    File.Delete(path);
    }
    File.Create(path).Close();
    File.WriteAllBytes(path, www.texture.EncodeToPNG());
    }