• 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
1
Question by georgios avate · Nov 11, 2015 at 01:33 PM · androidunity 5facebookcrashinglogin

unfortunately, app has stopped when trying to log into Facebook from mobile

I managed to incorporate the Facebook API into my project successfully, meaning, my game can take screenshots and post them into Facebook when clicking a button. However, this only works when running the application within the editor; touching that same button on my android device crashes the application instead (Unfortunately, appName has stopped).

I have been looking for a solution to this issue two days now, and while I came across a lot of different fixes, nothing seems to work; I already tried generating the correct hash key (with several different approaches), the apparently famous Rafael Fix, I tried fixing the screen orientation issue via AndroidManifest.xml, and I tried commenting the ScreenShot posting code (to make sure that Login is at fault).

I haven't made the app public on facebook, or uploaded to game to the play store yet (since it isnt ready for release yet anyways), but I don't think that should cause the game to crash like this.

I have a couple of days off my mandatory army service, and I really wanted to get this up and running before I had to go back to base. But, I am at my wit's end.

I'd really appreciate it if anyone could help me out with this.

Relevant Code:

   void Awake() {
 
         FB.Init(SetInit, OnHideUnity); 
     }
 
 
     private void SetInit() {
 
         print("FB: Init");
 
         if (FB.IsLoggedIn) print("FB: logged in");
 
         else print("FB: Not logged in");
     
     }
 
 
     public void FBLogin() {
 
         FB.LogInWithPublishPermissions(new List<string>() { "email", "publish_actions" }, AuthCallback);
         
     }
 
 
     void AuthCallback(ILoginResult result) {
 
         if (FB.IsLoggedIn) {
 
             print("FB: Login success");
             StartCoroutine(TakeScreenshot());
         }
 
         else print("FB: Login failure");
       
     }
 
 
 
     public void ShareScore() {
 
         if (!FB.IsLoggedIn) FBLogin();
     }
 
     
 
     private IEnumerator TakeScreenshot() {
 
         yield return new WaitForEndOfFrame();
         //print("W : " + Screen.width + " H : " + Screen.height); 
         var width = Screen.width;
         var height = Screen.height;
         var tex = new Texture2D(width, height, TextureFormat.RGB24, false);
 
         // Read screen contents into the texture
         tex.ReadPixels(new Rect(0, 0, width, height), 0, 0);
         tex.Apply();
         byte[] screenshot = tex.EncodeToPNG();
 
         var wwwForm = new WWWForm();
         wwwForm.AddBinaryData("image", screenshot, "InteractiveConsole.png");
         wwwForm.AddField("message", "herp derp.  I did a thing!  Did I do this right?");
         FB.API("me/photos", HttpMethod.POST, ShareCallback, wwwForm);
     }
     
 
 
     private void ShareCallback(IResult result) {
 
         if (result == null) {
 
             print("no result");     
             return;
         }
 
         // Some platforms return the empty string instead of null.
         if (!string.IsNullOrEmpty(result.Error)) print(result.ToString());
         
         else if (result.Cancelled) print("Cancelled");
         
         else if (!string.IsNullOrEmpty(result.RawResult)) print("Sucess, check log");
         
         else print("empty"); 
         
     }
 
 
     private void OnHideUnity(bool isGameShown) {
 
         print("FB: Hide Unity : " + !isGameShown);
        /* if (!isGameShown) Time.timeScale = 0;
         else Time.timeScale = 1;*/
     }
Comment
Add comment · Show 4
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
avatar image zzzzzz789 · Nov 12, 2015 at 06:10 PM 0
Share

What version of the Facebook SD$$anonymous$$ are you using? The latest is v7.2.2 available here. On the latest SD$$anonymous$$ you will replace the ShareCallback parameter with a IShareResult. Check the upgrade guide for details. Also be sure to walkthrough the Getting Started with Android.

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
4

Answer by VarelaByakko · Apr 19, 2016 at 02:48 AM

Your code work in your Editor but no in android phone.

You need to change this:

 public void FBLogin() {
  
          FB.LogInWithPublishPermissions(new List<string>() { "email", "publish_actions" }, AuthCallback);
  
 }

To this:

 public void FBLogin() {
  
          FB.LogInWithReadPermissions(new List<string>() { "email" }, AuthCallback);
          FB.LogInWithPublishPermissions(new List<string>() { "publish_actions" }, AuthCallback);
          
 }
Comment
Add comment · Show 1 · 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
avatar image subkiro · Dec 03, 2016 at 02:59 PM 0
Share

Thank you! this works perfect!

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to get a public profile permission facebook sdk 0 Answers

Unity facebook login without login dialog. 1 Answer

How to do communication between apps. ( Android ) 2 Answers

Facebook Login to create User account in my App 0 Answers

Broadcast Facebook Post To All App Users 0 Answers


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