Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by raincrowgames · Aug 10, 2016 at 03:13 PM · androidfacebook

Facebook Invitable Friends profile picture

Hey, I am trying to get the Profile Picture of the Facebook friends of the user who are not yet playing the game. I have retrieved their usernames successfully and just stuck on getting the profile picture. here is the code I am using (I followed this tutorial here )

 using UnityEngine;
 using System.Collections;
 using UnityEngine.UI;
 using Facebook.Unity;
 
 using System.Collections.Generic;
 
 
 public class FBLogin : MonoBehaviour {
 
     public GameObject login;
     public GameObject notLogin;
     public GameObject friend;
 
     void Awake()
     {
         if (!FB.IsInitialized) {
             FB.Init (InitCallBack);
         }
     }
 
     void InitCallBack()
     {
         print ("FB has Been Initialised");
     }
 
     public void Login()
     {
         if (!FB.IsLoggedIn) {
             FB.LogInWithReadPermissions(new List<string>{"user_friends"}, LoginCallBack);
         }
     }
 
      void LoginCallBack(ILoginResult result){
         if (result.Error == null) {
             Debug.Log ("Fb logged in!");
             login.SetActive (true);
             notLogin.SetActive (false);
             FB.API ("me/picture?width=100&height=100", HttpMethod.GET, PictureCallBack);
             FB.API ("me?fields=first_name", HttpMethod.GET, NameCallBack);
             FB.API ("me/invitable_friends", HttpMethod.GET, FriendCallBack);
 
         } else {
             login.SetActive (false);
             notLogin.SetActive(true);
         }
     }
 
     void PictureCallBack(IGraphResult result)
     {
         Texture2D image = result.Texture;
         login.transform.FindChild ("Image").GetComponent<Image> ().sprite = Sprite.Create (image, new Rect (0, 0, 100, 100), new Vector2 (.5f, .5f));
     }
 
     void NameCallBack(IGraphResult result)
     {
         IDictionary<string,object> profile = result.ResultDictionary;
 
         login.transform.GetChild (0).GetComponent<Text> ().text = "Hello, " + profile ["first_name"];
     }
     public void LogOut()
     {
         FB.LogOut ();
         login.SetActive (false);
         notLogin.SetActive (true);
 
     }
 
     public void Invite (){
         FB.AppRequest (message: "You Really should try this game.", title: "Covens");
     }
 
     public void Share(){
         FB.ShareLink (new System.Uri ("http://www.raincrowstudios.com/"), "This game is awesome!", "Discription about the game", new System.Uri ("http://www.raincrowstudios.com/images/covens_mast825.png"));
     }
     void FriendCallBack(IGraphResult result)
     {
         IDictionary<string, object> data = result.ResultDictionary;
         List<object> friends = (List<object>)data ["data"];
         foreach (object obj in friends) {
             Dictionary<string,object> dictio = (Dictionary<string,object>)obj;
             CreateFriend(dictio ["name"].ToString () , dictio ["id"].ToString());
         }
     }
 
     void CreateFriend(string name, string id){
         GameObject myFriend = Instantiate (friend);
         Transform parent = login.transform.FindChild("users");
         myFriend.transform.SetParent (parent);
         myFriend.transform.localScale = new Vector3 (1, 1, 1);
         myFriend.GetComponentInChildren<Text> ().text = name;
         FB.API ("me/invitable_friends/access_token="+id+"?fields=picture?width=100&height=100", HttpMethod.GET, delegate(IGraphResult result) {
             myFriend.GetComponent<Image> ().sprite = Sprite.Create (result.Texture, new Rect (0, 0, 100, 100), new Vector2 (.5f, .5f));
         });
 
 
     }
 }
 

I tried a bunch of ways to get the profile pictures none worked, I can't find the right syntax for it, would really appreciate it if someone can help me with this.

Thanks, Mridul

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image sharwood · Mar 21, 2017 at 06:03 AM 0
Share

@raincrowgames Did you ever solve this by chance - am struggling with this exact issue. Thanks

Shaun H

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by liortal · Mar 23, 2017 at 07:00 AM

When calling the method FB.API, you should also specify which fields (what data) you'd like the call to return. Here's an example:

 FB.API ("/me/invitable_friends?limit=5000&fields=id,name,picture.width(65).height(60).type(normal)", HttpMethod.GET, response => OnInvitableFriendsResponse);

Here, i am calling the invitable_friends API, and ask it to return certain fields about my invitable friends (id, name, picture).

You should then look at how the data is returned in jSON. the picture property contains a bunch of fields (width, height and a picture URL which you can use to retrieve the friend profile picture).

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by charles01 · Mar 23, 2017 at 08:47 PM

This works! just got it to work today thank after lots of searches :)

                 FB.API("https" + "://graph.facebook.com/" + user["id"].ToString() + "/picture?type=large", HttpMethod.GET, delegate (IGraphResult result)
                 {
                      fImage.overrideSprite = Sprite.Create(result.Texture, new Rect(0, 0, 200 , 125), new Vector2(0.5f, 0.5f), 100);
                 });
Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image kemosaleh55 · Oct 30, 2017 at 11:29 AM 0
Share

what is user in user["id"]?

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Too Many heap Sections - on Building to Android 1 Answer

Facebook Integration for Android Game 1 Answer

I have openSSL, but FB Plugin say's I don't? 1 Answer

Facebook Login restarts app on android 0 Answers

Facebook unity sdk: is it possible to send friend invites/app requests to non app users ? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges