-3

I am working in Unity.

I tried to post the score to the Facebook wall using Facebook SDK plugin.

Though I used a device (Nexus7, MotoG) with the official Facebook application installed, the FB.Feed() method is not working and dialog does not appear in device.

I tried the solution on Facebook Unity SDK on Android - Login fails when FB App installed, but it doesn't work for me.

Here is my fblogin script:

    public class fblogin : MonoBehaviour
{

        private string status = "Ready";
        private string lastResponse = "";
        public GUIStyle textStyle = new GUIStyle ();
        private Texture2D lastResponseTexture;
        private bool isInit = false;

        // Use this for initialization
        void Start ()
        {

        }

        // Update is called once per frame
        void Update ()
        {

        }

        void OnGUI ()
        {

                if (GUI.Button (new Rect (10, 10, 300, 100), "FB.Init")) {
                        CallFBInit ();
                        status = "FB.Init() called with " + FB.AppId;

                }

                if (GUI.Button (new Rect (100, 100, 300, 100), "Login")) {
                        //FB.Init (OnInitComplete, OnHideUnity);
                        //status = "FB.Init() called with " + FB.AppId;
                        CallFBLogin ();
                }

                if (GUI.Button (new Rect (200, 200, 300, 100), "Share")) {
                        //FB.Init (OnInitComplete, OnHideUnity);
                        //status = "FB.Init() called with " + FB.AppId;
                        onBragClicked ();      
                }





        }

        private void onBragClicked ()
        {                                                                                                                            
                //Util.Log ("onBragClicked");                                                                                            
                FB.Feed (
                linkCaption: "I just smashed " + "15" + " friends! Can you beat it?",               
                picture: "http://www.friendsmash.com/images/logo_large.jpg",                                                     
                linkName: "Checkout my Friend Smash greatness!",                                                                 
                link: "http://apps.facebook.com/" + FB.AppId + "/?challenge_brag=" + (FB.IsLoggedIn ? FB.UserId : "guest")       
                );                                                                                                               
        }

        private void CallFBInit ()
        {
                FB.Init (OnInitComplete, OnHideUnity);
        }

        private void OnInitComplete ()
        {
                Debug.Log ("FB.Init completed: Is user logged in? " + FB.IsLoggedIn);
                isInit = true;
        }

        private void OnHideUnity (bool isGameShown)
        {
                Debug.Log ("Is game showing? " + isGameShown);
        }

        private void CallFBLogin ()
        {
                FB.Login ("email,publish_actions", LoginCallback);
        }

        void LoginCallback (FBResult result)
        {
                if (result.Error != null)
                        lastResponse = "Error Response:\n" + result.Error;
                else if (!FB.IsLoggedIn) {
                        lastResponse = "Login cancelled by Player";
                } else {
                        lastResponse = "Login was successful!";
                }
        }
      }

Can anyone help?

Community
  • 1
  • 1
Abhishek Patel
  • 4,280
  • 1
  • 24
  • 38

1 Answers1

1

put this inside your script and in the inspector fill in all the FeedParameters, i think it is because you dont specify the Callback in your feed but put this in your script and fill in the parameters in the inspector, some of these feilds are required or else the feed wont even come up

#region FB.Feed() example

    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[]>();

    void Callback(FBResult result)
    {
        //lastResponseTexture = null;
        // Some platforms return the empty string instead of null.
        //if (!String.IsNullOrEmpty(result.Error)){
            //lastResponse = "Error Response:\n" + result.Error;
        //}
        //else if (!ApiQuery.Contains("/picture")){
            //lastResponse = "Success Response:\n" + result.Text;
        //}
        //else
        //{
            //lastResponseTexture = result.Texture;
            //lastResponse = "Success Response:\n";
        //}
    }

    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: Callback
            );
    }

    #endregion
JRowan
  • 6,824
  • 8
  • 40
  • 59
  • 1
    ok, that's right...but if i tried with uninstall the facebook application and than after ,it is successfully post on fb wall. – Abhishek Patel Apr 15 '14 at 13:32
  • i dont know, idk(i dont know) – JRowan Apr 16 '14 at 05:30
  • it is working fine when the fb app is not installed but its not working when the fb app is installed , see the response i am getting when i login in through fb app is "Login Cancelled by user".. – Abhishek Patel Apr 16 '14 at 05:44
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/50748/discussion-between-abhishek-patel-and-jrowan) – Abhishek Patel Apr 16 '14 at 05:45