Esempio n. 1
0
        async void WebView_LoadFinished(object sender, EventArgs e)
        {
            var url   = webView.EvaluateJavascript("window.location.href");
            var match = Provider == "Vimeo" ? Constants.VimeoRedirectURL : Constants.YouTubeRedirectURL;

            if (!url.StartsWith(match))
            {
                return;
            }
            var split = url.Split('=');

            if (split.Length == 0)
            {
                return;
            }
            var code = split [split.Length - 1];

            foreach (var view in View.Subviews)
            {
                view.RemoveFromSuperview();
            }

            var text = new UILabel(new CoreGraphics.CGRect(0, 0, 400, 90));

            text.Text          = "Loading...";
            text.TextAlignment = UITextAlignment.Center;
            text.Center        = View.Center;
            text.TextColor     = UIColor.Black;
            View.Add(text);

            InvokeInBackground(delegate {
                if (Provider == "Vimeo")
                {
                    var hook = VimeoHook.Authorize(
                        authCode: code,
                        clientId: Constants.VimeoAPIKey,
                        secret: Constants.VimeoAPISecret,
                        redirect: Constants.VimeoRedirectURL);
                    InvokeOnMainThread(delegate {
                        text.Text = string.Format("Logged in as {0}!", hook.User ["name"].Value);
                    });
                }
                else if (Provider == "YouTube")
                {
                    var hook = YouTubeHook.Authorize(
                        authCode: code,
                        clientId: Constants.YouTubeAPIKey,
                        secret: Constants.YouTubeAPISecret,
                        redirect: Constants.YouTubeRedirectURL);
                    InvokeOnMainThread(delegate {
                        text.Text = string.Format("Logged in as {0}!", hook.DisplayName);
                    });
                }
            });
        }
Esempio n. 2
0
 void BtnAuthVimeo_TouchUpInside(object sender, EventArgs e)
 {
     switchToAuth("Vimeo", VimeoHook.GetLoginURL(
                      clientId: Constants.VimeoAPIKey,
                      redirect: Constants.VimeoRedirectURL));
 }
Esempio n. 3
0
        protected override void OnStart()
        {
            base.OnStart();
            NotificationHandler.CancelNotification(this);
            VimeoHook.VerboseCallback = (o) => Console.WriteLine(o);
            Settings.LoadInfos();

            var code = string.Empty;

            try
            {
                var urlparams = Uptred.Core.QueryParametersFromUrl(Intent.Data.ToString());
                code = urlparams["code"];
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Settings.VimeoHook = null;
            }
            if (code != string.Empty)
            {
                try
                {
                    Settings.VimeoHook = VimeoHook.Authorize(
                        authCode: code,
                        clientId: ApiKeys.VimeoClientId,
                        secret: ApiKeys.VimeoClientSecret,
                        redirect: ApiKeys.VimeoRedirectURL);
                    Console.WriteLine("Logged in as " + Settings.VimeoHook.User["name"].ToString());
                    Settings.VimeoAccessToken = Settings.VimeoHook.AccessToken;
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    Settings.VimeoHook = null;
                }
            }
            else
            {
                try
                {
                    Settings.VimeoHook = VimeoHook.ReAuthorize(
                        accessToken: Settings.VimeoAccessToken,
                        clientId: ApiKeys.VimeoClientId,
                        redirect: ApiKeys.VimeoRedirectURL);
                    Console.WriteLine("Logged in as " + Settings.VimeoHook.User["name"].ToString());
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    Settings.VimeoHook = null;
                }
            }

            if (Settings.VimeoHook == null)
            {
                StartActivity(new Intent(Intent.ActionView, Uri.Parse(
                                             VimeoHook.GetLoginURL(clientId: ApiKeys.VimeoClientId, redirect: ApiKeys.VimeoRedirectURL))));
            }
            else
            {
                FindViewById <TextView>(Resource.Id.lblVerifier).Text = Settings.VimeoHook.User["name"].ToString();
            }
        }