Search Unity

Facebook UnityPackage doesn't work

Discussion in 'Android' started by ravinder, Nov 13, 2013.

  1. ravinder

    ravinder

    Joined:
    Aug 25, 2010
    Posts:
    150
    Hi everyone,

    I have been working on a game in which it is required to integrate Facebook sharing so I have grabbed the package which is provided by Facebook itself. It is working absolutely fine on iOS, it's just not giving expected results on Android.
    The SDK just initializes itself and then does nothing.

    I have set up the class, hashkey and package name exactly as it appears inside Unity under Facebook settings. The SDK version is the latest one 4.x and Unity's version is 4.2.2

    If anyone has integrated that package and encounters with this problem then please provide a working solution (if any).

    Thanks in advance

    Ravinder
     
  2. All_American

    All_American

    Joined:
    Oct 14, 2011
    Posts:
    1,528
    What isn't working? The example?
     
  3. ravinder

    ravinder

    Joined:
    Aug 25, 2010
    Posts:
    150
    Thank you for replying. After SDK gets initialized login functionality doesn't work. I have even tried building their demo scene and the login button never become active.
     
  4. All_American

    All_American

    Joined:
    Oct 14, 2011
    Posts:
    1,528
    Did you create an app in the app center in the facebook dev settings?

    You have to input the hash key there as well.

    Post your code here and everything you're doing.

    It is kind of tricky to get fb working.
     
  5. ravinder

    ravinder

    Joined:
    Aug 25, 2010
    Posts:
    150
    Hi,

    As I have mentioned in my post that I have added all the required fields viz. package name, class name and hash key on the facebook developer page but it's still not working. Even their own demo scene isn't working.
     
  6. All_American

    All_American

    Joined:
    Oct 14, 2011
    Posts:
    1,528
    Try only logging in with "publish_actions" and not "email".
     
  7. ravinder

    ravinder

    Joined:
    Aug 25, 2010
    Posts:
    150
    I understand but the problem is login is never allowed or there is no popup being shown to ask for.
     
  8. All_American

    All_American

    Joined:
    Oct 14, 2011
    Posts:
    1,528
    Post your code buddy.
     
  9. ravinder

    ravinder

    Joined:
    Aug 25, 2010
    Posts:
    150
    Hi,

    Please download the facebook latest unitypackage from here. Just go through the interactive scene's script. If you have an android device, you may also try to make a build with the demo scene to see if it's working or not.

    Thanks
     
  10. All_American

    All_American

    Joined:
    Oct 14, 2011
    Posts:
    1,528
    I have the FB sdk working. You're the one asking for help.....:|
     
  11. ravinder

    ravinder

    Joined:
    Aug 25, 2010
    Posts:
    150
    Yes of course but my point is even their own demo scene isn't working. Do you have the same package working at your end?
     
  12. All_American

    All_American

    Joined:
    Oct 14, 2011
    Posts:
    1,528
    It will not work in the editor. Yes it is working on my end.

    You have to build it out for it actually to work.

    That's why I asked to see your code so I could see if it is set up right. Like mine.
     
  13. ravinder

    ravinder

    Joined:
    Aug 25, 2010
    Posts:
    150
    Of course I know it won't work inside editor. I have tested it on the device.

    Here it is
    Code (csharp):
    1.  
    2. void FacebookButton()
    3.     {    
    4.         if(!isInit)
    5.             CallFBInit();
    6.        
    7.         else
    8.         {
    9.             if(!FB.IsLoggedIn)
    10.             {
    11.                 CallFBLogin();
    12.             }
    13.            
    14.             else
    15.             {
    16.                 CallFBFeed();
    17.             }
    18.         }
    19.     }
    20.  
    Here are the callbacks
    Code (csharp):
    1.  
    2. private void CallFBInit()
    3.     {
    4.         FB.Init(OnInitComplete, OnHideUnity);
    5.     }
    6.  
    7.  
    8.     private void OnInitComplete()
    9.     {
    10.         isInit = true;
    11.         Debug.Log("FB.Init completed: Is user logged in? " + FB.IsLoggedIn);
    12.     }
    13.    
    14.     private void OnHideUnity(bool isGameShown)
    15.     {
    16.         Debug.Log("Is game showing? " + isGameShown);
    17.     }
    18.    
    19.     private void CallFBLogin()
    20.     {
    21.         FB.Login("email,publish_actions", Callback);
    22.     }
    23.    
    24.     void Callback(FBResult result)
    25.     {
    26.         string lastResponse = string.Empty;
    27.         if (result.Error != null)
    28.             lastResponse = "Error Response:\n" + result.Error;
    29. //        else if (!ApiQuery.Contains("/picture"))
    30. //            lastResponse = "Success Response:\n" + result.Text;
    31.         else
    32.         {
    33. //            lastResponseTexture = result.Texture;
    34.             lastResponse = "Success Response:\n";
    35.         }
    36.     }
    37.    
    38.     private void CallFBPublishInstall()
    39.     {
    40.         FB.PublishInstall(PublishComplete);
    41.     }
    42.  
    43.  
    44.     private void PublishComplete(FBResult result)
    45.     {
    46.         Debug.Log("publish response: " + result.Text);
    47.     }
    48.    
    49.     private void CallFBFeed()
    50.     {
    51.         Dictionary<string, string[]> feedProperties = null;
    52.        
    53.         FB.Feed("",
    54.             "https://www.facebook.com/digital.world.studio",
    55.             "GameName",
    56.             "Awesome game","",
    57.             "http://www.digitalworldstudio.com/uploads/4/8/5/9/485987/1381779373.png",
    58.             "","","","",
    59.             feedProperties,
    60.             Callback);
    61.     }
    62.  
     
  14. All_American

    All_American

    Joined:
    Oct 14, 2011
    Posts:
    1,528
    Line 20 take out the "email" There is a bug when you try to get read and write permissions at the same time.
     
  15. ravinder

    ravinder

    Joined:
    Aug 25, 2010
    Posts:
    150
    Okay thank you for pointing out this. I will test it on the device and post it here. By the way it's weird that the same code works fine for iOS but not for Android
     
  16. ravinder

    ravinder

    Joined:
    Aug 25, 2010
    Posts:
    150
    with or without email?
     
  17. All_American

    All_American

    Joined:
    Oct 14, 2011
    Posts:
    1,528
    Get rid of this function to...There is issues with that for android as well I believe.

    "private void CallFBPublishInstall()" get rid of the entire function.
     
  18. All_American

    All_American

    Joined:
    Oct 14, 2011
    Posts:
    1,528

    Without.


    Code (csharp):
    1.  
    2. private void CallFBLogin()
    3. {
    4. if(!FB.Islogged)
    5. {
    6. FB.Login("publish_actions", Callback);
    7. }
    8.  }
    9.  
    10.  
    Also, make sure that the login activity is in portrait mode. In the Manifest.
     
  19. All_American

    All_American

    Joined:
    Oct 14, 2011
    Posts:
    1,528
    Just so you know, everytime you make changes on the FB site dev settings, it can take a few days for the changes to happen.
     
  20. ravinder

    ravinder

    Joined:
    Aug 25, 2010
    Posts:
    150
    Hi All_American,

    I have tested the build on the device by making amendments as per your suggestions but still not working.
    Any other suggestions?
     
  21. All_American

    All_American

    Joined:
    Oct 14, 2011
    Posts:
    1,528
    Post your manifest.
     
  22. ravinder

    ravinder

    Joined:
    Aug 25, 2010
    Posts:
    150
    Okay I noticed that there are multiple Manifest files available in my project. I am using Prime31 plugin for twitter and Tapjoy for Ads.
    Please find all the manifest files here.
     
  23. All_American

    All_American

    Joined:
    Oct 14, 2011
    Posts:
    1,528
    Can't DL anything here nor would anyway. Use the code tags and post it. Having multiple manifests could be your problem as well as using prime31 and the fb sdk together.
     
  24. ravinder

    ravinder

    Joined:
    Aug 25, 2010
    Posts:
    150
    FB SDK version
    Code (csharp):
    1.  
    2. <?xml version="1.0" encoding="utf-8"?>
    3. <manifest
    4.     xmlns:android="http://schemas.android.com/apk/res/android"
    5.     package="com.unity3d.player"
    6.     android:installLocation="preferExternal"
    7.     android:versionCode="1"
    8.     android:versionName="1.0">
    9.    
    10.     <supports-screens
    11.         android:smallScreens="true"
    12.         android:normalScreens="true"
    13.         android:largeScreens="true"
    14.         android:xlargeScreens="true"
    15.         android:anyDensity="true"/>
    16.    
    17.     <uses-permission android:name="android.permission.INTERNET" />
    18.     <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    19.     <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    20.     <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    21.  
    22.  
    23.     <application
    24.         android:icon="@drawable/app_icon"
    25.         android:label="@string/app_name">
    26.         <activity android:name="com.chartboost.sdk.unity.CBUnityPlayerProxyActivity"
    27.                   android:label="@string/app_name"
    28.                   android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen">
    29.             <intent-filter>
    30.                 <action android:name="android.intent.action.MAIN" />
    31.                 <category android:name="android.intent.category.LAUNCHER" />
    32.             </intent-filter>
    33.         </activity>
    34.         <activity android:name="com.chartboost.sdk.unity.CBUnityPlayerActivity"
    35.                   android:label="@string/app_name"
    36.                   android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen">
    37.         </activity>
    38.         <activity android:name="com.chartboost.sdk.unity.CBUnityPlayerNativeActivity"
    39.                   android:label="@string/app_name"
    40.                   android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen">
    41.             <meta-data android:name="android.app.lib_name" android:value="unity" />
    42.             <meta-data android:name="unityplayer.ForwardNativeEventsToDalvik" android:value="true" />
    43.         </activity>
    44.         <activity android:name="com.unity3d.player.VideoPlayer"
    45.                   android:label="@string/app_name"
    46.                   android:screenOrientation="behind"
    47.                   android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen">
    48.         </activity>
    49.    
    50.         <activity android:name="com.chartboost.sdk.CBImpressionActivity"
    51.             android:excludeFromRecents="true" android:theme="@android:style/Theme.Translucent.NoTitleBar" />
    52.     </application>
    53.  
    54.  
    55. </manifest>
    56.  
    57.  
    Prime31 version
    Code (csharp):
    1.  
    2. <!-- ACTIVITIES -->
    3.         <activity android:name="com.facebook.LoginActivity"></activity>
    4.         <activity android:name="com.prime31.FacebookProxyActivity"></activity>
    5.         <meta-data android:name="com.facebook.sdk.ApplicationId" android:value="\ 463362900445928"/>
    6.  
    7.  
    8.  
    9.  
    10.  
    11.  
    12. <!-- PERMISSIONS -->
    13.     <uses-permission android:name="android.permission.INTERNET" />
    14.  
    15.  
    16.  
    17.  
    18.  
     
  25. All_American

    All_American

    Joined:
    Oct 14, 2011
    Posts:
    1,528
    In the FB sdk version Line 29-30 goes in after line 35.

    I don't think you can use both manifests...That could also be a problem.