Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Facebook SDK and GUI related issues.

Discussion in 'Scripting' started by ManiaCCC, Dec 29, 2015.

  1. ManiaCCC

    ManiaCCC

    Joined:
    Aug 15, 2015
    Posts:
    41
    Hello,

    I am trying very simple Facebook integration into unity. I have empty space with just simple code:


    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using Facebook.Unity;
    5.  
    6. public class FBholder : MonoBehaviour {
    7.  
    8.     void Awake ()
    9.     {
    10.         FB.Init (SetInit, OnHideUnity);
    11.     }
    12.  
    13.     private void SetInit()
    14.     {
    15.         Debug.Log ("FB init done.");
    16.  
    17.         if (FB.IsLoggedIn) {
    18.             Debug.Log ("FB Logged In");
    19.         } else {
    20.             FBlogin ();      
    21.         }
    22.     }
    23.  
    24.     private void OnHideUnity(bool isGameShown){
    25.    
    26.         if (!isGameShown) {
    27.             Time.timeScale = 0;
    28.         } else {
    29.             Time.timeScale = 1;
    30.         }
    31.     }
    32.  
    33.     void FBlogin(){
    34.  
    35.         List<string> perms = new List<string>() { "public_profile, email", "user_friends" };
    36.         FB.LogInWithReadPermissions(perms, AuthCallback);
    37.  
    38.     }
    39.  
    40.     void AuthCallback(ILoginResult result)
    41.     {
    42.         if (FB.IsLoggedIn) {
    43.             Debug.Log ("FB login worked!");
    44.         } else {
    45.             Debug.Log ("FB Login failed");      
    46.         }
    47.     }
    48. }
    49.  
    And after run, I am getting this series of errors..basically every frame.

    and
    Can anyone please point me on somerelevant source of informations, tutorials or something? Everything I am getting while googling is not really helping at all.

    Thank you for any answer.
     
  2. Recon03

    Recon03

    Joined:
    Aug 5, 2013
    Posts:
    839
    Code (CSharp):
    1. public void FBLogin()
    2.     {
    3.         FB.Login("user_about_me", AuthCallBack);
    4.     }

    One issue I see is there. I will check the rest shortly.
     
  3. ManiaCCC

    ManiaCCC

    Joined:
    Aug 15, 2015
    Posts:
    41

    Thank you for reaction. :) I had that before, problem is FB.Login was replaced in latest facebook SDK with "FB.LogInWithReadPermissions" and "FB.LogInWithPublishPermissions". I had hard times to figure out how to set that login and I found this code on this forum. Script compiled without errors and warnings, however during runtime, I have streams of errors I mentioned above.
     
  4. Recon03

    Recon03

    Joined:
    Aug 5, 2013
    Posts:
    839
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using System.Collections.Generic;
    4.  
    5.  
    6.  
    7.  
    8.  
    9.     // Use this for initialization
    10.     public class FBholder : MonoBehaviour {
    11.        
    12.         void Awake ()
    13.         {
    14.             FB.Init (SetInit, OnHideUnity);
    15.         }
    16.        
    17.         private void SetInit()
    18.         {
    19.             Debug.Log ("FB init done.");
    20.            
    21.             if (FB.IsLoggedIn) {
    22.                 Debug.Log ("FB Logged In");
    23.             } else {
    24.                 FBlogin ();    
    25.             }
    26.         }
    27.        
    28.         private void OnHideUnity(bool isGameShown){
    29.            
    30.             if (!isGameShown) {
    31.                 Time.timeScale = 0;
    32.             } else {
    33.                 Time.timeScale = 1;
    34.             }
    35.         }
    36.        
    37.         void FBlogin(){
    38.            
    39.             //List<string> perms = new List<string>() { "public_profile, email", "user_friends" };
    40.             ///FB.LogInWithReadPermissions(perms, AuthCallback);
    41.         FB.Login("user_about_me", AuthCallback);
    42.            
    43.         }
    44.        
    45.     void AuthCallback(FBResult loginResults)
    46.         {
    47.             if (FB.IsLoggedIn) {
    48.                 Debug.Log ("FB login worked!");
    49.             } else {
    50.                 Debug.Log ("FB Login failed");    
    51.             }
    52.         }
    53.     }
    54.  

    tested and works.
     
  5. Recon03

    Recon03

    Joined:
    Aug 5, 2013
    Posts:
    839
    What version are you using of Facebook SDK, and Unity, just tested this and works great.
     
  6. ManiaCCC

    ManiaCCC

    Joined:
    Aug 15, 2015
    Posts:
    41
    Unity is 5.3 and Facebook SDK - 7.3.0

    EDIT: With your code I am getting "Facebook.Unity.FB' does not contain a definition for `Login'" error. :/
     
  7. Munchy2007

    Munchy2007

    Joined:
    Jun 16, 2013
    Posts:
    1,732
    In the facebook script that is causing the error replace GUI.ModelWindow(.... with GUI.Window(...

    The whole line is something like
    Code (CSharp):
    1. GUI.ModelWindow(GetHashCode(), new Rect(windowLeft, windowTop, windowWidth, windowHeight), OnGUIDialog, "Unity Editor Facebook Login");
    2.  
    it's the GUI.ModelWindow() that causes the problem, and it works perfectly well with GUI.Window()

    Edit: BTW there was nothing wrong with your original Login() code.
     
    Last edited: Dec 29, 2015
  8. ManiaCCC

    ManiaCCC

    Joined:
    Aug 15, 2015
    Posts:
    41
    Thank you, you are most probably right, this may be the issue. However it seems they changed folder structure and file structure and I just can't find that script which has this line of code in it. Is there way to look through all scripts at once? ( EditorFacebookAccessToken.cs file doesn't exists anymore)
     
  9. ManiaCCC

    ManiaCCC

    Joined:
    Aug 15, 2015
    Posts:
    41
    Now this is weird. I found script (i was stupid) with o ModalWindow...changed it to just Window as mentioned above and same thing..same errors. However..when I paused, changed script back to ModalWindow (during runtime) and unpaused, I got Login dialog on the screen. Tested this many times and still the same when I run the game as Window, pause, change back to ModalWindow, unpause and dialog is up..

    However it doesn't help much because when I enter token into dialog, scripts tell me I didn't call FB.Init() ...
     
  10. Recon03

    Recon03

    Joined:
    Aug 5, 2013
    Posts:
    839

    Ya you had some errors on the script you showed us, but I did not look at your error messages since it had a ton and I took your word for it, that it was related to that script..Now looking at it, it looks GUI related... as well, but you still have issues with your facebook script as well, I updated to 5.3.2 since that is what the new SDK from Facebook is using... So you have a bunch of small issues that you will need to tackle one at a time... then come back and people give us all of the correct info next time.. Thanks.
     
  11. felipeerpk

    felipeerpk

    Joined:
    Apr 9, 2013
    Posts:
    6
    Hi,

    I don't know if this is related to your issues, but there is a bug in Facebook SDK 7.3.0 related to the MockDialog in the Unity Editor. Facebook is already aware of this and will push the fix on the next update:

    https://developers.facebook.com/bugs/412005298997939/

    I fixed it temporary with the post recommendation, to change the OnGUI method in the EditorFacebookMockDialog.cs:

    Code (CSharp):
    1. public void OnGUI()
    2. {
    3.     if (this.modalStyle == null) {
    4.         this.modalRect = new Rect(10, 10, Screen.width - 20, Screen.height - 20);
    5.         Texture2D texture = new Texture2D(1, 1);
    6.         texture.SetPixel(0, 0, new Color(0.2f, 0.2f, 0.2f, 1.0f));
    7.         texture.Apply();
    8.         this.modalStyle = new GUIStyle(GUI.skin.window);
    9.         this.modalStyle.normal.background = texture;
    10.     }
    11.     GUI.ModalWindow(
    12.         this.GetHashCode(),
    13.         this.modalRect,
    14.         this.OnGUIDialog,
    15.         this.DialogTitle,
    16.         this.modalStyle);
    17. }
    And if you are using Facebook SDK 7.3.0 you should use "FB.LogInWithPublishPermissions" there is an example page with code: https://developers.facebook.com/docs/unity/examples
     
  12. Munchy2007

    Munchy2007

    Joined:
    Jun 16, 2013
    Posts:
    1,732
    Surely you only need to ask for publish permissions when and if you need them, otherwise only requesting read permissions is the preferred way to go.
     
  13. deiva

    deiva

    Joined:
    Jul 12, 2016
    Posts:
    16
    When i implement the Facebook score API in iOS build the game crashed But in android it works. Any solution for it.
    For IOS we should do any thing setting changes in editor or in build.
     
    Last edited: Jul 13, 2016
  14. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,146
    @ManiaCCC The issue you got is related to a bug in that version of the SDK. Update your facebook sdk to fix that error.
    Facebook stuff requires 'using Facebook.Unity;' not Facebook.Unity.FB
     
  15. deiva

    deiva

    Joined:
    Jul 12, 2016
    Posts:
    16
    k. i will update and inform you