- Home /
Unity Facebook SDK For Android Crashes when Logged in
I m developing an android Application , in which i connect to facebook , i get my Facebook User Info, invite my facebook friends and publish a link for my application in my Facebook Wall. I created a 3 GUI Buttons for that.
The problem that after i login , get my Facebook User info but after that the application crashes. Here is my code:
 using UnityEngine;
 using System.Collections;
 using System;
 using Facebook; 
 using Facebook.MiniJSON;
 using System.Collections.Generic;
 using System.Linq;
 
 
 public class InitAndLoginToFB : MonoBehaviour
 
 {   
 
 bool isEnabled;
 
 bool isLogged;
 
 string userId;
 
 public string get_data;
 
 public string fbName;
 
 public string fbId;
 
 public string fbMail;
 
 public string fbFirstName;
 
 public string fbLastName;
 
 
 public GUIText guiuser;
 
 public GUIText feedd;
 
 void Awake()
 
 {
 
     isEnabled = false;
 
     isLogged = false;
 
     userId = "not received";
 
 }
 
 
 
 private void SetInitFB()
 
 {
 
     isEnabled = true;
 
 }
 
 
 
 private void SetAvailability(bool a_status)
 
 {
 
 }
 
 
 
 void LoginCallBack(FBResult result)
 
 {
 
     if (result.Error != null)
 
     {
 
         Debug.Log("Receive callback login error :: " + result.Error.ToString());
 
     }
 
     else
 
     {
 
         if (FB.IsLoggedIn)
 
         {
 
             isLogged = true;
 
             userId = FB.UserId;
 
 
 
         }
 
         else
 
         {
 
             isLogged = false;
 
         }
 
     }
 
 }
 
 void Start()
 
 {
 
     // Must call FB.Init Once
 
     FB.Init(SetInitFB, SetAvailability);
 
 }
 
 void callBackUserInfo()
 {
 
     FB.API("me?fields=name,id,email,first_name,last_name", Facebook.HttpMethod.GET, UserCallBack);
 
 }
 
 void UserCallBack(FBResult result)
 {
     if (result.Error != null)
     {                                                                      
         get_data = result.Text;
     }
     else
     {
         get_data = result.Text;
     }
     var dict = Json.Deserialize(get_data) as IDictionary;
     fbName =dict ["name"].ToString();
     fbId = dict ["id"].ToString ();
     fbMail = dict["email"].ToString();
     fbFirstName = dict["first_name"].ToString();
     fbLastName = dict["last_name"].ToString();
     guiuser.text = " Username" + fbName + " userId " + fbId + " First Name " + fbFirstName + " Last Name " + fbLastName + " Mail " + fbMail;
 }
 
 void OnGUI()
 
 {
 
     if (isEnabled)
 
     {
 
         if (!isLogged)
 
         {
 
             if (GUI.Button(new Rect(5, 5, 100, 40), "Login FB"))
 
             {
 
                 FB.Login("email", LoginCallBack);
 
             }
 
         }
 
         else
 
         {
 
             GUI.Label(new Rect(120, 5, 200, 40), userId);
 
             callBackUserInfo();
 
             if(GUI.Button(new Rect(30,100,100,40),"Feed"))
             {
                 CallFBFeed();
             }
 
             if (GUI.Button(new Rect(30, 150, 100, 40), "Invite"))
             {
                 CallAppRequestAsFriendSelector();
             }
 
         }
 
     }
 
 }
 
 public string FeedToId = "";
 public string FeedLink = "";
 public string FeedLinkName = "";
 public string FeedLinkCaption = "";
 public string FeedLinkDescription = "";
 public string FeedPicture = "";
 public string FeedMediaSource = "";
 public string FeedActionName = "";
 public string FeedActionLink = "";
 public string FeedReference = "";
 public bool IncludeFeedProperties = false;
 private Dictionary<string, string[]> FeedProperties = new Dictionary<string, string[]>();
 
 private void CallFBFeed()
 {
     Dictionary<string, string[]> feedProperties = null;
     if (IncludeFeedProperties)
     {
         feedProperties = FeedProperties;
     }
     FB.Feed(
         toId: FeedToId,
         link: FeedLink,
         linkName: FeedLinkName,
         linkCaption: FeedLinkCaption,
         linkDescription: FeedLinkDescription,
         picture: FeedPicture,
         mediaSource: FeedMediaSource,
         actionName: FeedActionName,
         actionLink: FeedActionLink,
         reference: FeedReference,
         properties: feedProperties,
         callback: LogCallback
         );
 }
 
 void LogCallback(FBResult response)
 {
     var responseObject = Json.Deserialize(response.Text) as Dictionary<string, object>;
     object cancelled;
     if (responseObject.TryGetValue ("cancelled", out cancelled))
     {
         if( (bool)cancelled == true )
         {
             feedd.text = "not publish";
         }
         else
         {
             feedd.text = "publish";
         }
     }
     else
     {
         feedd.text = "publish";
     }
 }
 
 #region FB.AppRequest() Friend Selector
 
 public string FriendSelectorTitle = "";
 public string FriendSelectorMessage = "Derp";
 public string FriendSelectorFilters = "[\"all\",\"app_users\",\"app_non_users\"]";
 public string FriendSelectorData = "{}";
 public string FriendSelectorExcludeIds = "";
 public string FriendSelectorMax = "";
 
 private void CallAppRequestAsFriendSelector()
 {
     // If there's a Max Recipients specified, include it
     int? maxRecipients = null;
     if (FriendSelectorMax != "")
     {
         try
         {
             maxRecipients = Int32.Parse(FriendSelectorMax);
         }
         catch (Exception e)
         {
             //status = e.Message;
         }
     }
 
     // include the exclude ids
     string[] excludeIds = (FriendSelectorExcludeIds == "") ? null : FriendSelectorExcludeIds.Split(',');
 
     FB.AppRequest(
         FriendSelectorMessage,
         null,
         FriendSelectorFilters,
         excludeIds,
         maxRecipients,
         FriendSelectorData,
         FriendSelectorTitle,
         LogCallbackk
     );
 }
 #endregion  
 void LogCallbackk(FBResult responsee)
 {
     Debug.Log(responsee.Text);
 }
 }
Thanks for your help
               Comment
              
 
               
              Answer by BranditDEV · Oct 18, 2016 at 06:14 PM
Try this and consider those two lines I commented (they crash android too)
 void Login(){
 List<string> permissions = new List<string>();
         permissions.Add("public_profile");
        // permissions.Add("publish_actions");
      //   permissions.Add("user_friends");
 
         FB.LogInWithReadPermissions(permissions, AuthCallback);
 }
 void AuthCallback(IResult result)
 {
         if (result.Error != null)
         {
             print(result.Error);
         }
         else
         {
             if (FB.IsLoggedIn) { print("Succes login."); }
             else { print("Failed login."); }
         }
         HandleLoginMenuFacebook(FB.IsLoggedIn);
 }
Your answer
 
 
             Follow this Question
Related Questions
Help Facebook SDK 0 Answers
Facebook Login restarts app on android 0 Answers
Too Many heap Sections - on Building to Android 1 Answer
Facebook Integration for Android Game 1 Answer
A node in a childnode? 1 Answer
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                