1
votes

I'm using the Unity Facebook SDK for my iOS game but FB.Feed isn't working. Using Unity 4.2.2 and Facebook SDK 4.2.4

Here's what happens:

  • Upon Game Start, FB init is called

    void Awake () {
        enabled = false;
        FB.Init(SetInit, OnHideUnity);
    }
    
    private void SetInit()
    {
        enabled = true; // "enabled" is a magic global
        FB.GetAuthResponse(LoginCallback);
    }
    
    private void OnHideUnity(bool isGameShown)
    {
        if (!isGameShown)
        {
            Time.timeScale = 0;
        }
        else
        {
            Time.timeScale = 1;
        }
    }
    
    void LoginCallback(FBResult result)
    {
    Debug.Log("call login: " + FB.UserId);
        FbDebug.Log("call login: " + FB.UserId);
        Debug.Log("login result: " + result.Text);
        FbDebug.Log("login result: " + result.Text);
        if (result.Error != null)
        {
            Debug.LogError(result.Error);
            return;
        }
    }
    
  • When I click the button for sharing on facebook, the following function is called:

    public void FBShare() {
        if(!FB.IsLoggedIn)
            FB.Login("email,publish_actions", LoginCallback);
        FB.Feed(
            linkName: "My Game",
            linkDescription: "Just played My Game. It's awesome!",
            linkCaption: "I just smashed 4" + " friends! Can you beat it?",
            picture: "http://www.friendsmash.com/images/logo_large.jpg",
            callback: LogCallback
        );
    }
    
  • If I'm not logged in, then I get a login prompt on facebook (switching to the FB app)

  • If I haven't authorized the app, then I get a prompt for that as well.
  • And then the Facebook Share Feed appears with all the specified information I put in the function, all the previous steps working properly.
  • The problem starts once I touch the post button. The app starts uploading my post but then abruptly switches back to the game.

Tearing my hair out for the past 3 days. Can't find anything to help. Logs from the callback functions are return empty responses.

2

2 Answers

2
votes

Login is an asynchronous function. Once you call it it will multitask out of your app and try to authenticate. You are immediately calling Feed after calling login. Feed will also try to multitask out of your app. You make a custom login callback for this case and call feed from inside of it.

2
votes

I finally figured it out. The problem was an incorrect bundle ID on the Facebook app online, the changes took some time to propagate to all FB servers so it wasn't immediately apparent what was the problem.