Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Unity Facebook SDK - Android Deployement -

Discussion in 'Android' started by DaMex, Sep 24, 2013.

  1. DaMex

    DaMex

    Joined:
    Jul 12, 2012
    Posts:
    21
    Hi everyone, hope I m not in the wrong spot of the forum for this thread !
    Any ways, I got an issue to set up the latest version of the Unity Facebook SDK released, the 4.2.1
    (build version 130912.80d74183e6e5bd9)

    The problem that I m blocked at the app config step, following the documentation on facebook developer pages, it says that the SDK should be printing up the Key Hash for my app so I just have to copy / paste it the the facebook app config edition. But actually the Facebook Settings tool in Unity doesn't show up any key hash (nothing appears in front of Debug Android Key Hash), the app name and app ID are there, as much as the package and class name !

    I have a feeling that I m missing something stupid out there but after 3 hours trying to find any hint somewhere, ... I m just stucked.

    Any help please ?
     
  2. Shauli

    Shauli

    Joined:
    Sep 21, 2013
    Posts:
    1
    same problem for me!
     
  3. nan

    nan

    Joined:
    May 19, 2009
    Posts:
    10
    same problem on FacebookSDK-130826.unitypackage
     
  4. DaMex

    DaMex

    Joined:
    Jul 12, 2012
    Posts:
    21
    I dont know If I should be happy to see that I m not the only one in this case or be sad because we are still stuck
     
  5. jruntime

    jruntime

    Joined:
    Aug 18, 2012
    Posts:
    2
    I'm also having the same issue with FacebookSDK-130912.unitypackage and seem to be stucked there. I managed to get the hash keys out using keytool (as found in http://javatechig.com/android/how-to-get-key-hashes-for-android-facebook-app/ ), registered them to Facebook and made sure that Unity is using those keys, but that hasn't helped at all and the problem persist in the way described.
     
  6. swifer07

    swifer07

    Joined:
    May 27, 2013
    Posts:
    12
  7. jruntime

    jruntime

    Joined:
    Aug 18, 2012
    Posts:
    2
    That trick truly works, got it talk with FB now once entering the hash in FB, thanks a million!
     
  8. DaMex

    DaMex

    Joined:
    Jul 12, 2012
    Posts:
    21
    Hi everybody ! Glad to see that some of you could resolve their problem with the link provided by swifer07 so we thank him a lot :)

    But on my side I kept working on trying to make things more clear and specially after the release of the new FBUnity SDK 4.2.4 so here is what I came up with :

    Download Openssl, extract the archive, put the content of bin folder in C:\Program Files\Java\jdk1.7.0_06\bin (or your Java SDK Folder) and execute the following command in Command Prompt (cmd) :

    keytool -exportcert -alias androiddebugkey -keystore %HOMEPATH%\.android\debug.keystore | "C:\Program Files\Java\jdk1.7.0_06\bin\openssl.exe" sha1 -binary | "C:\Program Files\Java\jdk1.7.0_06\bin\openssl.exe" base64

    Of course please think about replacing : C:\Program Files\Java\jdk1.7.0_06\ with you local JDK installation folder path

    Important To know also, the right version of openssl tu use on windows 7 x64 with JDK version jdk1.7.0_40 (that's actually my config) is the version 0.9.8h-1 that you can download in zip format right here

    Now to make things clear and easy to understand, you can implement by yourself the SDK in the way that makes it clear for you (skip the example provided within the package you get from the Assets Store).

    First thing to do is make sure that you configured your application on facebook and on unity in the right way https://developers.facebook.com/docs/unity/getting-started/

    Then just create a new scene, create a single new script where you write down this (after you made sure that you did read it to understand it)

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4. using Facebook;        // Must be specified to use HTTpMethod class
    5.  
    6. public class InitAndLoginToFB : MonoBehaviour
    7. {
    8.  
    9.     bool isEnabled;
    10.     bool isLogged;
    11.     string userId;
    12.  
    13.     Texture pic;
    14.  
    15.     void Awake()
    16.     {
    17.         isEnabled = false;
    18.         isLogged = false;
    19.         userId = "not received";
    20.     }
    21.  
    22.     private void SetInitFB()
    23.     {
    24.         // This method method will be called withing the callback received by FB.Init()
    25.         isEnabled = true;
    26.     }
    27.  
    28.     private void SetAvailability(bool a_status)
    29.     {
    30.         // This method method will be called withing the callback received each time Unity gets or looses Focus (True/false)
    31.     }
    32.  
    33.     void LoginCallBack(FBResult result)
    34.     {
    35.         if (result.Error != null)
    36.         {
    37.             Debug.Log("Receive callback login error :: " + result.Error.ToString());
    38.         }
    39.         else
    40.         {
    41.             if (FB.IsLoggedIn)
    42.             {
    43.                 // Case login was successful
    44.                 isLogged = true;
    45.                 userId = FB.UserId;
    46.  
    47.             }
    48.             else
    49.             {
    50.                 // Case login failed (because of cancelling for example)
    51.                 isLogged = false;
    52.             }
    53.         }
    54.     }
    55.  
    56.     void GetProfilePicAnswer(FBResult response)
    57.     {
    58.         // This method method will be called withing the callback received by FB.API()
    59.         // You can add a control here for any kind of failure to print up a default picture for example
    60.         if (response.Texture != null)
    61.         {
    62.             pic = response.Texture;
    63.         }
    64.     }
    65.  
    66.     void Start()
    67.     {
    68.         // Must call FB.Init Once
    69.         FB.Init(SetInitFB, SetAvailability);
    70.     }
    71.  
    72.     void OnGUI()
    73.     {
    74.         if (isEnabled)
    75.         {
    76.             if (!isLogged)
    77.             {
    78.                 if (GUI.Button(new Rect(5, 5, 100, 40), "Login FB"))
    79.                 {
    80.                     // In the string you are sending within the login process you can specify wich "permissions" you are asking for (in this case only to get the user's email)
    81.                     FB.Login("email", LoginCallBack);
    82.                 }
    83.             }
    84.             else
    85.             {
    86.                 GUI.Label(new Rect(120, 5, 200, 40), userId);
    87.                 if (GUI.Button(new Rect(5, 5, 100, 40), "GetPic"))
    88.                 {
    89.                     FB.API("/me/picture", HttpMethod.GET, GetProfilePicAnswer);
    90.                 }
    91.             }
    92.  
    93.             if (pic != null)
    94.             {
    95.                 GUI.DrawTexture(new Rect((Screen.width - pic.width) / 2, (Screen.height - pic.height) / 2, pic.width, pic.height), pic);
    96.             }
    97.         }
    98.     }
    99. }
    100.  
    101.  
    102.  
     
  9. All_American

    All_American

    Joined:
    Oct 14, 2011
    Posts:
    1,528
    I am using the FB SDK to use it with a android game and I keep getting a message saying "unfortunately the app has stopped " when trying to login to facebook from the game.

    Any ideas?
     
  10. newlife

    newlife

    Joined:
    Jan 20, 2010
    Posts:
    1,056
    Same thing here. It seems that there is no way to make the facebook SDK work with android. And the fact the the official android tutorial video (https://www.youtube.com/watch?v=5g0WdYbq-dg#t=705) "skips" the part where it should show the demo in an actual Android device due to "not being set up to make a screen cast from an Android phone" that says it all.
     
  11. 00christian00

    00christian00

    Joined:
    Jul 22, 2012
    Posts:
    1,035
    Hi, I just made a thread about this.
    The windows version is broken, even after I managed to print the hash by modifying the editor it didn't work.
    Here is how to fix it :
    http://forum.unity3d.com/threads/222977-How-to-fix-Facebook-SDK-Android-Login

    Regarding the crash, I only tested their demos, maybe it's a compatibility issue with some JDK? It didn't work with my 64bit Java, now I'm using the latest 32 bit JDK with Android SDK 4.4
     
  12. rtumelty

    rtumelty

    Joined:
    Dec 11, 2011
    Posts:
    12
    DaMex, cheers for that! Was bugging me for a while.
     
  13. Adrian Pulido

    Adrian Pulido

    Joined:
    Feb 24, 2014
    Posts:
    1
    Hello, i have the same problem

    but, in the command for CMD: %HOMEPATH% = ?

    %HOMEPATH% is path of the archive .apk?

    which file should go this route?
     
  14. ymerk

    ymerk

    Joined:
    Nov 1, 2012
    Posts:
    4
    Hi all. Haven't read all of the answers, but encountered the same problem.
    I used the answer from the user vfxjex from this post which i think is a good solution. It worked very well.
     
  15. Bertlapp

    Bertlapp

    Joined:
    Sep 7, 2015
    Posts:
    44
    I have the same problem. Strange thing is the application worked fine before using the facebook sdk 7.4.0 with the environment variables linked for java and openssl in path.