public void ShowGameGroupJoinMockDialog(Utilities.Callback <ResultContainer> callback, string callbackId) { this.ShowEmptyMockDialog(callback, callbackId, "Mock Game Group Join"); }
public void ShowAppRequestMockDialog(Utilities.Callback <ResultContainer> callback, string callbackId) { this.ShowEmptyMockDialog(callback, callbackId, "Mock App Request"); }
public void ExternalCall(string functionName, object[] args) { this.LogMethodCall(functionName); IDictionary <string, object> result; Utilities.Callback <ResultContainer> callback = null; if (functionName == "FBUnity.init") { result = MockResults.GetGenericResult(0, this.ResultExtras); callback = this.Facebook.OnInitComplete; } else if (functionName == "FBUnity.logAppEvent") { // Workaround log the method call to match the signature of ios and android. this.LogMethodCall("LogAppEvent"); // No callback on log app event return; } else if (functionName == "FBUnity.login") { var permissions = (IEnumerable <string>)args[0]; var callbackID = int.Parse((string)args[1]); result = MockResults.GetLoginResult(callbackID, permissions, this.ResultExtras); callback = this.Facebook.OnLoginComplete; } else if (functionName == "FBUnity.ui") { var callbackMetod = (string)args[2]; var callbackID = int.Parse((string)args[1]); if (callbackMetod == Constants.OnGroupCreateCompleteMethodName) { result = MockResults.GetGroupCreateResult(callbackID, this.ResultExtras); callback = this.Facebook.OnGroupCreateComplete; } else if (callbackMetod == Constants.OnGroupJoinCompleteMethodName) { result = MockResults.GetGenericResult(callbackID, this.ResultExtras); callback = this.Facebook.OnGroupJoinComplete; } else if (callbackMetod == Constants.OnAppRequestsCompleteMethodName) { result = MockResults.GetGenericResult(callbackID, this.ResultExtras); callback = this.Facebook.OnAppRequestsComplete; } else if (callbackMetod == Constants.OnShareCompleteMethodName) { result = MockResults.GetGenericResult(callbackID, this.ResultExtras); callback = this.Facebook.OnShareLinkComplete; } else if (callbackMetod == Constants.OnPayCompleteMethodName) { result = MockResults.GetGenericResult(callbackID, this.ResultExtras); callback = this.CanvasFacebook.OnPayComplete; } else { throw new NotImplementedException("Mock missing ui function: " + callbackMetod); } } else { throw new NotImplementedException("Mock missing function: " + functionName); } callback(new ResultContainer(result)); }
private static void FormatAuthResponse(ResultContainer result, Utilities.Callback <ResultContainer> callback) { if (result.ResultDictionary == null) { callback(result); return; } IDictionary <string, object> authResponse; if (result.ResultDictionary.TryGetValue(CanvasFacebook.AuthResponseKey, out authResponse)) { result.ResultDictionary.Remove(CanvasFacebook.AuthResponseKey); foreach (var item in authResponse) { result.ResultDictionary[item.Key] = item.Value; } } // The JS SDK doesn't always store the permissions so request them before returning the results if (result.ResultDictionary.ContainsKey(LoginResult.AccessTokenKey) && !result.ResultDictionary.ContainsKey(LoginResult.PermissionsKey)) { var parameters = new Dictionary <string, string>() { { "fields", "permissions" }, { Constants.AccessTokenKey, (string)result.ResultDictionary[LoginResult.AccessTokenKey] }, }; FacebookDelegate <IGraphResult> apiCallback = (IGraphResult r) => { IDictionary <string, object> permissionsJson; if (r.ResultDictionary != null && r.ResultDictionary.TryGetValue("permissions", out permissionsJson)) { IList <string> permissions = new List <string>(); IList <object> data; if (permissionsJson.TryGetValue("data", out data)) { foreach (var permission in data) { var permissionDictionary = permission as IDictionary <string, object>; if (permissionDictionary != null) { string status; if (permissionDictionary.TryGetValue("status", out status) && status.Equals("granted", StringComparison.InvariantCultureIgnoreCase)) { string permissionName; if (permissionDictionary.TryGetValue("permission", out permissionName)) { permissions.Add(permissionName); } else { FacebookLogger.Warn("Didn't find permission name"); } } else { FacebookLogger.Warn("Didn't find status in permissions result"); } } else { FacebookLogger.Warn("Failed to case permission dictionary"); } } } else { FacebookLogger.Warn("Failed to extract data from permissions"); } result.ResultDictionary[LoginResult.PermissionsKey] = permissions.ToCommaSeparateList(); } else { FacebookLogger.Warn("Failed to load permissions for access token"); } callback(result); }; FB.API( "me", HttpMethod.GET, apiCallback, parameters); } else { callback(result); } }
private static void FormatAuthResponse(ResultContainer result, Utilities.Callback <ResultContainer> callback) { if (result.ResultDictionary == null) { callback(result); return; } IDictionary <string, object> dictionary; if (result.ResultDictionary.TryGetValue("authResponse", out dictionary)) { result.ResultDictionary.Remove("authResponse"); foreach (KeyValuePair <string, object> current in dictionary) { result.ResultDictionary[current.Key] = current.Value; } } if (result.ResultDictionary.ContainsKey(LoginResult.AccessTokenKey) && !result.ResultDictionary.ContainsKey(LoginResult.PermissionsKey)) { Dictionary <string, string> formData = new Dictionary <string, string> { { "fields", "permissions" }, { "access_token", (string)result.ResultDictionary[LoginResult.AccessTokenKey] } }; FacebookDelegate <IGraphResult> callback2 = delegate(IGraphResult r) { IDictionary <string, object> dictionary2; if (r.ResultDictionary != null && r.ResultDictionary.TryGetValue("permissions", out dictionary2)) { IList <string> list = new List <string>(); IList <object> list2; if (dictionary2.TryGetValue("data", out list2)) { foreach (object current2 in list2) { IDictionary <string, object> dictionary3 = current2 as IDictionary <string, object>; if (dictionary3 != null) { string text; if (dictionary3.TryGetValue("status", out text) && text.Equals("granted", StringComparison.InvariantCultureIgnoreCase)) { string item; if (dictionary3.TryGetValue("permission", out item)) { list.Add(item); } else { FacebookLogger.Warn("Didn't find permission name"); } } else { FacebookLogger.Warn("Didn't find status in permissions result"); } } else { FacebookLogger.Warn("Failed to case permission dictionary"); } } } else { FacebookLogger.Warn("Failed to extract data from permissions"); } result.ResultDictionary[LoginResult.PermissionsKey] = list.ToCommaSeparateList(); } else { FacebookLogger.Warn("Failed to load permissions for access token"); } callback(result); }; FB.API("me", HttpMethod.GET, callback2, formData); } else { callback(result); } }
public void CallStatic(string methodName, params object[] args) { this.LogMethodCall(methodName); Utilities.Callback <ResultContainer> callback = null; IDictionary <string, object> result; IDictionary <string, object> methodArguments = null; int callbackID = -1; if (args.Length == 1) { var jsonParams = (string)args[0]; if (jsonParams != null) { methodArguments = MiniJSON.Json.Deserialize(jsonParams) as IDictionary <string, object>; string callbackStr; if (methodArguments != null && methodArguments.TryGetValue(Constants.CallbackIdKey, out callbackStr)) { callbackID = int.Parse(callbackStr); } } } if (callbackID == -1 && methodName != "Init") { // There was no callback so just return; return; } if (methodName == "Init") { callback = this.MobileFacebook.OnInitComplete; result = MockResults.GetGenericResult(0, this.ResultExtras); } else if (methodName == "AppInvite") { callback = this.MobileFacebook.OnAppInviteComplete; result = MockResults.GetGenericResult(callbackID, this.ResultExtras); } else if (methodName == "GetAppLink") { callback = this.Facebook.OnGetAppLinkComplete; result = MockResults.GetGenericResult(callbackID, this.ResultExtras); } else if (methodName == "AppRequest") { callback = this.Facebook.OnAppRequestsComplete; result = MockResults.GetGenericResult(callbackID, this.ResultExtras); } else if (methodName == "FeedShare") { callback = this.Facebook.OnShareLinkComplete; result = MockResults.GetGenericResult(callbackID, this.ResultExtras); } else if (methodName == "ShareLink") { callback = this.Facebook.OnShareLinkComplete; result = MockResults.GetGenericResult(callbackID, this.ResultExtras); } else if (methodName == "GameGroupCreate") { callback = this.Facebook.OnGroupCreateComplete; result = MockResults.GetGroupCreateResult(callbackID, this.ResultExtras); } else if (methodName == "GameGroupJoin") { callback = this.Facebook.OnGroupJoinComplete; result = MockResults.GetGenericResult(callbackID, this.ResultExtras); } else if (methodName == "LoginWithPublishPermissions" || methodName == "LoginWithReadPermissions") { callback = this.Facebook.OnLoginComplete; string permissions; methodArguments.TryGetValue(AndroidFacebook.LoginPermissionsKey, out permissions); result = MockResults.GetLoginResult( callbackID, permissions, this.ResultExtras); } else if (methodName == "RefreshCurrentAccessToken") { callback = this.MobileFacebook.OnRefreshCurrentAccessTokenComplete; result = MockResults.GetLoginResult( callbackID, string.Empty, this.ResultExtras); } else { throw new NotImplementedException("Not implemented for " + methodName); } callback(new ResultContainer(result)); }