Esempio n. 1
0
        public void graphApi(string options)
        {
            var args        = JsonHelper.Deserialize <List <string> >(options);
            var apiPath     = args[0];
            var permissions = JsonHelper.Deserialize <string[]>(args[1]);

            Deployment.Current.Dispatcher.BeginInvoke(async() =>
            {
                if (string.IsNullOrEmpty(CurrentTokenData.AccessToken))
                {
                    DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, "No active sessions found"));
                    return;
                }

                if (CurrentTokenData.NeedNewPermissions(permissions))
                {
                    var permError = new PermissionsError
                    {
                        Code = "permissions_missing",
                        Uri  =
                            await GetDialogUri("oauth", LOGIN_REDIRECT_URI, new Dictionary <string, object>
                        {
                            { "auth_type", "rerequest" },
                            { "response_type", LOGIN_RESPONSE_TYPE },
                            { "scope", string.Join(",", permissions) }
                        })
                    };

                    DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, permError));
                    return;
                }

                await Session.CheckAndExtendTokenIfNeeded();

                try
                {
                    dynamic result = await FbClient.GetTaskAsync(apiPath);
                    DispatchCommandResult(new PluginResult(PluginResult.Status.OK, result.ToString()));
                }
                catch (Exception ex)
                {
                    DispatchCommandResult(new PluginResult(PluginResult.Status.IO_EXCEPTION, ex.Message));
                }
            });
        }
        public void graphApi(string options)
        {
            var args = JsonHelper.Deserialize<List<string>>(options);
            var apiPath = args[0];
            var permissions = JsonHelper.Deserialize<string[]>(args[1]);

            Deployment.Current.Dispatcher.BeginInvoke(async () =>
            {
                if (string.IsNullOrEmpty(CurrentTokenData.AccessToken))
                {
                    DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, "No active sessions found"));
                    return;
                }

                if (CurrentTokenData.NeedNewPermissions(permissions))
                {
                    var permError = new PermissionsError
                    {
                        Code = "permissions_missing",
                        Uri =
                            await GetDialogUri("oauth", LOGIN_REDIRECT_URI, new Dictionary<string, object>
                            {
                                {"auth_type", "rerequest"},
                                {"response_type", LOGIN_RESPONSE_TYPE},
                                {"scope", string.Join(",", permissions)}
                            })
                    };

                    DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, permError));
                    return;
                }

                await Session.CheckAndExtendTokenIfNeeded();

                try
                {
                    dynamic result = await FbClient.GetTaskAsync(apiPath);
                    DispatchCommandResult(new PluginResult(PluginResult.Status.OK, result.ToString()));
                }
                catch (Exception ex)
                {
                    DispatchCommandResult(new PluginResult(PluginResult.Status.IO_EXCEPTION, ex.Message));
                }

            });
        }