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 Kasa · Apr 24, 2014 at 11:48 AM · androidfacebooklogin

Facebook SDK v5.1 cannot login on android device

Hi, I get the trouble with using Facebook SDK on android. Below is what I have done:

  1. I'm using Facebook sdk 5.1.0 and Unity version is 4.3.4

  2. In "`Assets\Facebook\Editor\android\FacebookAndroidUtil.cs`", I add "`System.Environment.GetEnvironmentVariable("HOMEDRIVE")`" in line 62 so that "Debug Android Key Hash" can be generated.

  3. I using C# to type the main script, in "Awake()" I add "FB.Init(SetInit, InitCallback);". It just like the tutorial from developers.facebook.com, and enable is give out "true". (I think that mean FB.init() is success.)

After that, I build up a GUI button for log in. I have try "`FB.Login("basic_infos", AfterLogin);`", " FB.Login("publish_actions", AfterLogin); " and " FB.Login("email", AfterLogin); ", both the FB.isLoggedIn is false on android device.

Actually I can log in on unity environment using "User Access Token". On android device, after I press the Login button, it give out a permission and then I press "OK", nothing happen...(`FB.isLoggedIn` still false)

Anyone can give a help? I get the trouble a few week already...
p.s. My English is not good, please let me know if you don't understand.


Below is my coding,

 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 using Facebook.MiniJSON;
 using System;
 
 public class FB_control : MonoBehaviour {
 
     public Texture2D texture_btn_Login;    
 
     void Awake ()
     {
         FB.Init(SetInit);
     }
 
     public void SetInit()
     {
         enabled = true;
     }
 
     void OnGUI()
     {
         // Click
         if (GUI.Button(new Rect(10, 50, texture_btn_Login.width * 2, texture_btn_Login.height * 2), texture_btn_Login))
         {
             FB.Login("basic_infos", AfterLogin);
         }
 
         // Display
         GUI.Label(new Rect(10, 300, 400, 30), "Login: "+ FB.IsLoggedIn +"      ||  init.enabled: "+ enabled);
 
         if(api_get_result == true)
         {
             GUI.Label(new Rect(10, 500, 400, 30), "ID: "+ profile["id"]);
             GUI.Label(new Rect(10, 550, 400, 30), "Name: "+ profile["name"]);
         }
     }
     
     void AfterLogin(FBResult result)
     {
         if(FB.IsLoggedIn)
         {
             FB.API("/me?fields=id,name", Facebook.HttpMethod.GET, APICallback);
         }
     }
     
     void APICallback(FBResult result)                                                                                              
     {
         result_str = result.Text;
         profile = Util.DeserializeJSONProfile(result.Text);
     }
 }
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

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by maxoja · Apr 24, 2014 at 12:37 PM

Did you enable status & review feature on facebook to be public?

You can turned it on at developers.facebook.com

select your app and choose Statuc and Reviews in the left side.

This will be work only when you have correct keyhash

so if this solution doesn't help I suggest you'd better try to logcat to find correct keyhash.

Comment
Add comment · Show 5 · 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 Kasa · Apr 24, 2014 at 02:54 PM 0
Share

Hi $$anonymous$$axoja, I follow your suggest to go thought the facebook apps again. Now the submission is pending, I have to wait if it can approved or not.

avatar image maxoja · Apr 24, 2014 at 03:17 PM 0
Share

You don't need to start any submission , just switch the toggle on top left on to "yes" alt text

facebook sdk.png (44.5 kB)
avatar image Kasa · Apr 24, 2014 at 03:23 PM 0
Share

Really? The apps already switch on! But I still cannot log in on mobile...

P.S. I just add the new content. Hope that can help you understand more.

avatar image maxoja · Apr 24, 2014 at 04:19 PM 0
Share

Have you already tried to logcat your device? then check if keyhash you found in logcat command line is the same as you have generated.

I heard from many people that the key generated by keytool is wrong :)

avatar image Kasa · Apr 24, 2014 at 06:45 PM 0
Share

Hi $$anonymous$$axoja! You are right! I found many tutorial to learn how to generate log file (Because I don't know how to use "logcat"...), After that, I found that the key hash is not correct as you say!

Then put the right key to facebook app, the problem is solved! Thank you very much! :D

avatar image
0

Answer by vfxjex · Jul 13, 2014 at 04:11 PM

The main problem is the key hash that generate unity. The key which shows unity is different you have to put in facebook settings.

Here's the solution!

Unzip .apk file and extract META-INF\CERT.RSA file (like renaming your .apk to .zip)

run keytool -printcert -file CERT.RSA (paste this in cmd, make sure you are in the correct path)

notice SHA1 bytes are printed like 29:37:F1:CB:06…

copy SHA1 bytes into HEX to BASE64 converter (http://tomeko.net/online_tools/hex_to_base64.php?lang=en)

see your BASE64 key hash in output field

That Key BASE64 is the REAL key you have to put in facebook settings on https://apps.facebook.com/nameapp

from https://stackoverflow.com/questions/19670467/unable-to-login-with-facebook-sdk-for-unity-on-android/22780951#22780951?newreg=cd0f62d696ce42e68994ed1e66ab1564

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 Unity Ninja · Aug 05, 2014 at 05:28 AM 0
Share

So should I be using this as my only keyhash or just add this to the keyhashes(with the previous one that I got from unity).

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

When I start my game on Android this crashes (google play problem) 0 Answers

How to integrate new google play games services for leaderboard? 2 Answers

about Facebook SDK AppRequest.. 0 Answers

Login to Steam from Android app 0 Answers

How can i access facebook without entering access token in unity project??? 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