Beispiel #1
0
 public static void init(bool printKeyHash = true)
 {
     if (Application.platform != RuntimePlatform.Android)
     {
         return;
     }
     FacebookAndroid._facebookPlugin.Call("init", new object[]
     {
         printKeyHash
     });
     Facebook.instance.accessToken = FacebookAndroid.getAccessToken();
 }
Beispiel #2
0
 static FacebookAndroid()
 {
     if (Application.platform != RuntimePlatform.Android)
     {
         return;
     }
     using (AndroidJavaClass androidJavaClass = new AndroidJavaClass("com.prime31.FacebookPlugin"))
     {
         FacebookAndroid._facebookPlugin = androidJavaClass.CallStatic <AndroidJavaObject>("instance", new object[0]);
     }
     FacebookManager.preLoginSucceededEvent += delegate
     {
         Facebook.instance.accessToken = FacebookAndroid.getAccessToken();
     };
 }
Beispiel #3
0
    void OnGUI()
    {
        beginColumn();


        if (GUILayout.Button("Initialize Facebook"))
        {
            FacebookAndroid.init();
        }


        if (GUILayout.Button("Set Login Behavior to SUPPRESS_SSO"))
        {
            FacebookAndroid.setSessionLoginBehavior(FacebookSessionLoginBehavior.SUPPRESS_SSO);
        }


        if (GUILayout.Button("Login"))
        {
            FacebookAndroid.loginWithReadPermissions(new string[] { "email", "user_birthday" });
        }


        if (GUILayout.Button("Reauthorize with Publish Permissions"))
        {
            FacebookAndroid.reauthorizeWithPublishPermissions(new string[] { "publish_actions", "manage_friendlists" }, FacebookSessionDefaultAudience.Everyone);
        }


        if (GUILayout.Button("Logout"))
        {
            FacebookAndroid.logout();
        }


        if (GUILayout.Button("Is Session Valid?"))
        {
            var isSessionValid = FacebookAndroid.isSessionValid();
            Debug.Log("Is session valid?: " + isSessionValid);
        }


        if (GUILayout.Button("Get Session Token"))
        {
            var token = FacebookAndroid.getAccessToken();
            Debug.Log("session token: " + token);
        }


        if (GUILayout.Button("Get Granted Permissions"))
        {
            var permissions = FacebookAndroid.getSessionPermissions();
            Debug.Log("granted permissions: " + permissions.Count);
            Prime31.Utils.logObject(permissions);
        }


        endColumn(true);


        if (GUILayout.Button("Post Image"))
        {
            var pathToImage = Application.persistentDataPath + "/" + screenshotFilename;
            var bytes       = System.IO.File.ReadAllBytes(pathToImage);

            Facebook.instance.postImage(bytes, "im an image posted from Android", completionHandler);
        }


        if (GUILayout.Button("Graph Request (me)"))
        {
            Facebook.instance.graphRequest("me", completionHandler);
        }


        if (GUILayout.Button("Post Message"))
        {
            Facebook.instance.postMessage("im posting this from Unity: " + Time.deltaTime, completionHandler);
        }


        if (GUILayout.Button("Post Message & Extras"))
        {
            Facebook.instance.postMessageWithLinkAndLinkToImage("link post from Unity: " + Time.deltaTime, "http://prime31.com", "prime[31]", "http://prime31.com/assets/images/prime31logo.png", "Prime31 Logo", completionHandler);
        }


        if (GUILayout.Button("Show Share Dialog"))
        {
            var parameters = new Dictionary <string, object>
            {
                { "link", "http://prime31.com" },
                { "name", "link name goes here" },
                { "picture", "http://prime31.com/assets/images/prime31logo.png" },
                { "caption", "the caption for the image is here" },
                { "description", "description of what this share dialog is all about" }
            };
            FacebookAndroid.showFacebookShareDialog(parameters);
        }


        if (GUILayout.Button("Show Post Dialog"))
        {
            // parameters are optional. See Facebook's documentation for all the dialogs and paramters that they support
            var parameters = new Dictionary <string, string>
            {
                { "link", "http://prime31.com" },
                { "name", "link name goes here" },
                { "picture", "http://prime31.com/assets/images/prime31logo.png" },
                { "caption", "the caption for the image is here" }
            };
            FacebookAndroid.showDialog("stream.publish", parameters);
        }


        if (GUILayout.Button("Show Apprequests Dialog"))
        {
            // See Facebook's documentation for all the dialogs and paramters that they support
            var parameters = new Dictionary <string, string>
            {
                { "message", "Come play my awesome game!" }
            };
            FacebookAndroid.showDialog("apprequests", parameters);
        }


        if (GUILayout.Button("Get Friends"))
        {
            Facebook.instance.getFriends(completionHandler);
        }


        endColumn();


        if (bottomLeftButton("Twitter Scene"))
        {
            Application.LoadLevel("TwitterTestScene");
        }
    }
Beispiel #4
0
    void SetCallbacks()
    {
        Application.RegisterLogCallbackThreaded(HandleLog);

        /*GSApi.GSMessageReceived += (GS, args)=>
         * {
         *      if(args.Message["@class"] as string == ".ChallengeAcceptedMessage"){
         #if UNITY_ANDROID && !UNITY_EDITOR
         *              GCM.ShowToast("Challenge Accepted");
         #else
         *              if (Debug.isDebugBuild) Debug.Log("Challenge Accepted");
         #endif
         *      }
         *      else if(args.Message["@class"] as string == ".ChallengeDeclinedMessage"){
         #if UNITY_ANDROID && !UNITY_EDITOR
         *              GCM.ShowToast("Challenge Declined");
         #else
         *              if (Debug.isDebugBuild) Debug.Log("Challenge Accepted");
         #endif
         *      }
         *      else if(args.Message["@class"] as string == ".ChallengeChatMessage"){
         #if UNITY_ANDROID && !UNITY_EDITOR
         *              GCM.ShowToast("Challenge Chat Recieved");
         #else
         *              if (Debug.isDebugBuild) Debug.Log("Challenge Chat Recieved");
         *              GameGlobals.messageCount++;
         #endif
         *      }
         *
         * };*/
#if UNITY_ANDROID && !UNITY_EDITOR
        FacebookManager.sessionOpenedEvent += delegate()
        {
            if (Debug.isDebugBuild)
            {
                Debug.Log("facebook callback worked");
            }



            //we assume that this can will only be called if session is invalid or we are on a new device.

            Hashtable response = GSApi.facebookConnect(FacebookAccess.getAccessToken());

            if ((string)response["@class"] == ".AuthenticationResponse" && (string)response["authToken"] != null)
            {
                GameGlobals.online = true;
                Hashtable details = GSApi.accountDetails();


                if (details["userId"] != null)
                {
                    GameGlobals.userID = (string)details["userId"];
                }
                if (!GCM.IsRegistered())
                {
                    GCM.Register();
                }
                GSApi.registerForPush(GCM.GetRegistrationId());
            }
            else
            {
                GameGlobals.online = false;
            }
        };
#endif



#if UNITY_ANDROID && !UNITY_EDITOR
        GCM.SetErrorCallback((string errorId) => {
            if (Debug.isDebugBuild)
            {
                Debug.Log("Error!!! " + errorId);
            }
            GCM.ShowToast("Error!!!");
            _text = "Error: " + errorId;
        });

        GCM.SetMessageCallback((Dictionary <string, object> table) => {
            if (Debug.isDebugBuild)
            {
                Debug.Log("Message!!!");
            }
            GCM.ShowToast("Message!!!");
            _text = "Message: " + System.Environment.NewLine;
            foreach (var key in  table.Keys)
            {
                _text += key + "=" + table[key] + System.Environment.NewLine;
            }
        });



        GCM.SetRegisteredCallback((string registrationId) => {
            //if(FacebookAccess.isSessionValid() &&
        });
#endif
    }