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 mrgeorge3d · Mar 25, 2016 at 08:02 AM · facebookpictureprofile

Facebook Profile pic Callback don't Execute

Hi, I'm trying to get the user's profile pic and my "ProfilePicCallback" it's not getting executed. What am I Missing?

P.S. This code works perfectly inside unity editor and I can get the name and picture of the user however when I test on iOS the PictureCallback never gets executed and I can only get the username.

This is my code:

 using UnityEngine;
 using System.Collections;
 using UnityEngine.UI;


 public class FacebookLoginOpt : MonoBehaviour 
 {
 //Diccionario para obtener los datos del usuario de Facebook
 IDictionary dict;

 public GameObject fbLoginBtn;

 private string fbName;

 private GameObject loginCanvas;


 public void FBLogin()
 {
     if (!FB.IsLoggedIn) 
     {
         if (InternetConnection.control.IsConnectedToInternet ()) {
             //Login With Facebook
             FB.Login ("public_profile,user_friends,user_birthday,publish_actions", LoginCallback);
             fbLoginBtn.GetComponent<Button> ().enabled = false;
         } else {

             //Instantiate Facebook Login Canvas
             GameObject thePrefab;
             GameObject getPrefab = Resources.Load <GameObject> ("MyPrefabs/Facebook_Failed_Canvas");
             thePrefab = (GameObject)Instantiate (getPrefab, transform.position,transform.rotation);
             fbLoginBtn.GetComponent<Button> ().enabled = true;


         }
     }
 }

 void LoginCallback(FBResult result)
 {
     if (FB.IsLoggedIn) 
     {
         GetUserData ();
     }
 }

 void GetUserData()
 {
     FB.API ("/me?fields=id,first_name,last_name,gender,birthday,relationship_status", Facebook.HttpMethod.GET, GetUserDataCallback);

     //Get Profile Pic
     FB.API (Util.GetPictureURL ("me", 128, 128), Facebook.HttpMethod.GET,ProfilePicCallback );

     //Instantiate Canvas
     GameObject thePrefab;
     GameObject getPrefab = Resources.Load <GameObject> ("MyPrefabs/Activity_Canvas");
     thePrefab = (GameObject)Instantiate (getPrefab, transform.position,transform.rotation);


 }

 void GetUserDataCallback(FBResult result)
 {
     if(result.Error != null)
     {
         FB.API ("/me?fields=id,first_name,last_name,gender,birthday,relationship_status", Facebook.HttpMethod.GET, GetUserDataCallback);
         Debug.Log("Se quedó en estancado");
         Debug.Log(result.Error);
         return;
     }

     Destroy (GameObject.Find ("Activity_Canvas(Clone)").gameObject);
     GameObject.Find ("FB_Login").gameObject.SetActive (false);

     Resources.UnloadUnusedAssets ();


     dict = Facebook.MiniJSON.Json.Deserialize (result.Text) as IDictionary;

     fbName = dict ["first_name"].ToString ();

     print ("The name is " + fbName );
 }

 void ProfilePicCallback(FBResult result)
 {
     if (result.Error != null && result.Texture == null) {
         Debug.LogWarning ("Problema al obtener la foto de perfil de facebook");
         FB.API (Util.GetPictureURL ("me", 128, 128), Facebook.HttpMethod.GET, ProfilePicCallback);
         return;
     } else {

 

         //Instantiate Canvas
         GameObject getPrefab = Resources.Load <GameObject> ("MyPrefabs/Facebook_Login_Canvas");
         loginCanvas = (GameObject)Instantiate (getPrefab, transform.position,transform.rotation);

         GameObject.Find ("FacebookPic").GetComponent<Image> ().sprite = Sprite.Create (result.Texture, new Rect (0, 0, 128, 128), new Vector2 (0.5f, 0.5f));
         Debug.Log ("Se creó el facebook Canvas");

         //Change Text to the username
         GameObject.Find ("FacebookPic").GetComponent<Image> ().sprite = Sprite.Create (result.Texture, new Rect (0, 0, 128, 128), new Vector2 (0.5f, 0.5f));
         GameObject.Find ("Greet").GetComponent<Text> ().text = "Hello " + fbName;
     }
 }

 }
Comment
Add comment · Show 2
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 zzzzzz789 · Mar 25, 2016 at 09:17 AM 0
Share

FB.API is asynchronous and as such you probably shouldn't fire multiple requests to the API at the same time. Ins$$anonymous$$d... try calling FB.API (Util.GetPictureURL... in the callback for GetUserData.

Also... You have coded a potentially infinite loop if the FB.API always returns an error, you might want to prevent that.

avatar image mrgeorge3d · Mar 25, 2016 at 06:55 PM 0
Share

Thanks for your comment.

I tried to call FB.API((Util.GetPictureURL... in the callback for GetUserData and it didn't work... Is it possible to make a coroutine for the facebook login? Would that be a good idea?

0 Replies

· Add your reply
  • Sort: 

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

38 People are following this question.

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

Related Questions

facebook profile pic not working 0 Answers

Displaying profile pictures in all connected devices 1 Answer

Facebook Friend Pictures Returning Blank on Leaderboard 0 Answers

facebook and soomla sdk error 0 Answers

why the Facebook sdk unable to merge android manifests ? 2 Answers


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