Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 IronGirl · Jun 04, 2014 at 11:45 AM · androidfacebook

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
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

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);
 }
Comment
Add comment · Share
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

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

22 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

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


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