diff --git a/UnitySDK/Assets/FacebookSDK/Examples/Scripts/MenuBase.cs b/UnitySDK/Assets/FacebookSDK/Examples/Scripts/MenuBase.cs index e1d46ff18..a4f16d039 100644 --- a/UnitySDK/Assets/FacebookSDK/Examples/Scripts/MenuBase.cs +++ b/UnitySDK/Assets/FacebookSDK/Examples/Scripts/MenuBase.cs @@ -75,6 +75,49 @@ protected void HandleResult(IResult result) LogView.AddLog(result.ToString()); } + protected void HandleLimitedLoginResult(IResult result) + { + if (result == null) + { + this.LastResponse = "Null Response\n"; + LogView.AddLog(this.LastResponse); + return; + } + + this.LastResponseTexture = null; + + // Some platforms return the empty string instead of null. + if (!string.IsNullOrEmpty(result.Error)) + { + this.Status = "Error - Check log for details"; + this.LastResponse = "Error Response:\n" + result.Error; + } + else if (result.Cancelled) + { + this.Status = "Cancelled - Check log for details"; + this.LastResponse = "Cancelled Response:\n" + result.RawResult; + } + else if (!string.IsNullOrEmpty(result.RawResult)) + { + this.Status = "Success - Check log for details"; + this.LastResponse = "Success Response:\n" + result.RawResult; + } + else + { + this.LastResponse = "Empty Response\n"; + } + + String resultSummary = "Limited login results\n\n"; + var profile = FB.Mobile.CurrentProfile(); + resultSummary += "name: " + profile.Name + "\n"; + resultSummary += "id: " + profile.UserID + "\n"; + resultSummary += "email: " + profile.Email + "\n"; + resultSummary += "pic URL: " + profile.ImageURL + "\n"; + resultSummary += "friends: " + String.Join(",", profile.FriendIDs) + "\n"; + + LogView.AddLog(resultSummary); + } + protected void OnGUI() { if (this.IsHorizontalLayout()) diff --git a/UnitySDK/Assets/FacebookSDK/Examples/Scripts/SubMenus/MainMenu.cs b/UnitySDK/Assets/FacebookSDK/Examples/Scripts/SubMenus/MainMenu.cs index a56b33ffb..2ccabe766 100644 --- a/UnitySDK/Assets/FacebookSDK/Examples/Scripts/SubMenus/MainMenu.cs +++ b/UnitySDK/Assets/FacebookSDK/Examples/Scripts/SubMenus/MainMenu.cs @@ -45,19 +45,37 @@ protected override void GetGui() GUILayout.BeginHorizontal(); GUI.enabled = enabled && FB.IsInitialized; - if (this.Button("Login")) + if (this.Button("Classic login")) { - this.CallFBLogin(); - this.Status = "Login called"; + this.CallFBLogin("enabled"); + this.Status = "Classic login called"; } - - GUI.enabled = FB.IsLoggedIn; if (this.Button("Get publish_actions")) { this.CallFBLoginForPublish(); this.Status = "Login (for publish_actions) called"; } + GUILayout.EndHorizontal(); + GUILayout.BeginHorizontal(); + + if (this.Button("Limited login")) + { + this.CallFBLogin("test"); + this.Status = "Limited login called"; + + } + if (this.Button("Limited login +friends")) + { + this.CallFBLogin("test+friends"); + this.Status = "Limited login +friends called"; + + } + + + GUI.enabled = FB.IsLoggedIn; + + // Fix GUILayout margin issues GUILayout.Label(GUIContent.none, GUILayout.MinWidth(ConsoleBase.MarginFix)); GUILayout.EndHorizontal(); @@ -118,9 +136,25 @@ protected override void GetGui() GUI.enabled = enabled; } - private void CallFBLogin() + private void CallFBLogin(string enabled="enabled") { - FB.LogInWithReadPermissions(new List() { "public_profile", "email", "user_friends" }, this.HandleResult); + List scopes = new List(); + scopes.Add("public_profile"); + if(enabled=="test+friends") + { + scopes.Add("user_friends"); + } + + + if(enabled=="enabled") + { + FB.Mobile.LoginWithTrackingPreference(LoginTracking.ENABLED, scopes, "classic_nonce123", this.HandleResult); + } + else + { + FB.Mobile.LoginWithTrackingPreference(LoginTracking.LIMITED, scopes, "limited_nonce123", this.HandleLimitedLoginResult); + } + } private void CallFBLoginForPublish()