• 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 greaneagle · Dec 02, 2015 at 03:40 PM · androidunity5facebooksdk

Facebook SDK v7.2 login not working when on android

Hello, so here is my problem. I am using tthe newest Unity and Facebook SDk. What I want to do is have a facebook login on the menu screen of my game and a share button if the player is logged in.

I got it all to work just fine in the editor, the login with the token and share work like they should (I think) But when I bulild the app and put it on android, the game works fine, but when I click my login button, the Facebook window pops up like it should but it says "Error, you are not logged in"

Um.... well yeah, I am not logged in since I just pressed the login button. I cant figure this one out. Did anyone have a similar problem with the new SDK? If not I will post my code of my login and shar scripts and would apreciate any help :)

Thank you!

Comment
Add comment · Show 1
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 · Dec 02, 2015 at 05:06 PM 0
Share

I recommend you start with the 'Getting Started' guides to get up and running with the SD$$anonymous$$ sample on Android: https://developers.facebook.com/docs/unity/gettingstarted https://developers.facebook.com/docs/unity/getting-started/android https://developers.facebook.com/docs/unity/examples

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by phil_me_up · Dec 02, 2015 at 06:42 PM

It sounds like you might be trying to share before you're logged in (i.e. an issue with your logic). If you post the code you use to decide what action to take when the button is pressed it will help find the problem.

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
avatar image
0

Answer by greaneagle · Dec 02, 2015 at 09:15 PM

phill_me_up I dont know why but I couldnt reply to your anwser so my reply is here.

Nope, that is not it, I always check if its logged in before doing anything. Also thie error apears when I click the button that only does the login and no sharing. But thank you for your reply.

I will add my code here. Please take a look and I am sorry if it's just a noobish mistake I missed. This code is what I put together from the examples thata are on the Facebook developers website.

 using UnityEngine;
 using System.Collections;
 using Facebook.Unity;
 using System.Collections.Generic;
 
 public class FBscript : MonoBehaviour {
 
     // Include Facebook namespace
     public GameObject fbButton; // Assign in inspector
 
     // Awake function from Unity's MonoBehavior
     void Awake()
 {
     if (!FB.IsInitialized)
     {
         // Initialize the Facebook SDK
         FB.Init(InitCallback, OnHideUnity);
     }
     else
     {
         // Already initialized, signal an app activation App Event
         FB.ActivateApp();
     }
 
         
     
 }
 
      void Start() {
          if (FB.IsLoggedIn)
          {
              fbButton.SetActive(false);
          }
          else
          {
          fbButton.SetActive(true);
 
          }
 
 
      }
 
     private void InitCallback()
 {
     if (FB.IsInitialized)
     {
         // Signal an app activation App Event
         FB.ActivateApp();
         // Continue with Facebook SDK
         // ...
     }
     else
     {
         Debug.Log("Failed to Initialize the Facebook SDK");
     }
 }
 
 private void OnHideUnity(bool isGameShown)
 {
     if (!isGameShown)
     {
         // Pause the game - we will need to hide
         Time.timeScale = 0;
     }
     else
     {
         // Resume the game - we're getting focus again
         Time.timeScale = 1;
     }
 }
     public void loginFunction()
     {
         if (FB.IsLoggedIn)
         {
             Debug.Log("User already logged in!");
         }
         else
         {
           
             var perms = new List<string>() { "public_profile", "email", "user_friends" };
             FB.LogInWithReadPermissions(perms, AuthCallback);
             
         }
     }
 
 private void AuthCallback(ILoginResult result)
     {
         if (FB.IsLoggedIn)
         {
             // AccessToken class will have session details
             var aToken = Facebook.Unity.AccessToken.CurrentAccessToken;
             // Print current access token's User ID
             Debug.Log(aToken.UserId);
             // Print current access token's granted permissions
             foreach (string perm in aToken.Permissions)
             {
                 Debug.Log(perm);
             }
             fbButton.SetActive(false);
 
         }
         else
         {
             fbButton.SetActive(true);
             Debug.Log("User cancelled login");
         }
     }
 
 }
 

I have a button on the scene that runs the public function loginFunction() And that is all I can say about it.... I dont understand what goes wrong after that.

Comment
Add comment · Show 2 · 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 meat5000 ♦ · Dec 02, 2015 at 09:16 PM 0
Share

Answer must be less than 3000 characters to be converted to comment.

avatar image zzzzzz789 · Dec 03, 2015 at 12:09 AM 0
Share

Code looks fine, check your app configuration settings on the Facebook developer site. Also can you share more about the error you see (screenshot too).

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

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

7 People are following this question.

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

Related Questions

Android app crashes on launch after removing Facebook SDK 1 Answer

App Invite not showing notification to friends in facebook 2 Answers

Facebook sdk 7.9 with Unity 5.4.2f2 and Android sdk compatibility !? 1 Answer

How to remove Facebook SDK from project when I don't need that? 1 Answer

Facebook SDK login problem on Android 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges