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); }); } }); }
public static void Auth(Queue<string> parameters) { var url = YouTubeHook.GetLoginURL( clientId: Constants.GetYouTubeAPIKey(), redirect: Constants.GetYouTubeRedirectURL()); App.Info("Open this URL and follow the instructions:"); App.Info(url); if (parameters.Count > 0 && parameters.First().ToLower() == "ie") { parameters.Dequeue(); var psi = new ProcessStartInfo("iexplore.exe"); psi.Arguments = url; Process.Start(psi); } Console.Write("Enter authCode> "); var authcode = Console.ReadLine(); try { yc = YouTubeHook.Authorize( authCode: authcode, clientId: Constants.GetYouTubeAPIKey(), secret: Constants.GetYouTubeAPISecret(), redirect: Constants.GetYouTubeRedirectURL()); Settings.Default.YouTubeRefresh = yc.RefreshToken; Settings.Default.Save(); App.Info("Logged in as " + yc.DisplayName); login = true; } catch { App.Error("Error logging in."); return; } }
void BtnAuthYouTube_TouchUpInside(object sender, EventArgs e) { switchToAuth("YouTube", YouTubeHook.GetLoginURL( clientId: Constants.YouTubeAPIKey, redirect: Constants.YouTubeRedirectURL)); }
protected override void OnStart() { base.OnStart(); NotificationHandler.CancelNotification(this); YouTubeHook.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.YouTubeHook = null; } if (code != string.Empty) { try { Settings.YouTubeHook = YouTubeHook.Authorize( authCode: code, clientId: ApiKeys.YouTubeClientId, secret: ApiKeys.YouTubeClientSecret, redirect: ApiKeys.YouTubeRedirectURL); Console.WriteLine("Logged in as " + Settings.YouTubeHook.DisplayName); Settings.YouTubeRefreshToken = Settings.YouTubeHook.RefreshToken; } catch (Exception e) { Console.WriteLine(e.Message); Settings.YouTubeHook = null; } } else { try { Settings.YouTubeHook = YouTubeHook.ReAuthorize( refreshToken: Settings.YouTubeRefreshToken, clientId: ApiKeys.YouTubeClientId, secret: ApiKeys.YouTubeClientSecret, redirect: ApiKeys.YouTubeRedirectURL); Console.WriteLine("Logged in as " + Settings.YouTubeHook.DisplayName); } catch (Exception e) { Console.WriteLine(e.Message); Settings.YouTubeHook = null; } } if (Settings.YouTubeHook == null) { StartActivity(new Intent(Intent.ActionView, Uri.Parse( YouTubeHook.GetLoginURL(clientId: ApiKeys.YouTubeClientId, redirect: ApiKeys.YouTubeRedirectURL)))); } else { FindViewById <TextView>(Resource.Id.lblVerifier).Text = Settings.YouTubeHook.DisplayName; } }
public static bool Login() { try { if (!login) { yc = YouTubeHook.ReAuthorize( refreshToken: Settings.Default.YouTubeRefresh, clientId: Constants.GetYouTubeAPIKey(), secret: Constants.GetYouTubeAPISecret(), redirect: Constants.GetYouTubeRedirectURL()); App.Info("Logged in as " + yc.DisplayName); login = true; } } catch { App.Error("Error logging in."); return false; } return login; }
public static void Login(Queue<string> parameters) { string authcode = ""; if (parameters.Count > 0) authcode = parameters.Dequeue(); if (string.IsNullOrWhiteSpace(authcode)) { login = false; Login(); return; } try { yc = YouTubeHook.Authorize( authCode: authcode, clientId: Constants.GetYouTubeAPIKey(), secret: Constants.GetYouTubeAPISecret(), redirect: Constants.GetYouTubeRedirectURL()); Settings.Default.YouTubeRefresh = yc.RefreshToken; Settings.Default.Save(); App.Info("Logged in as " + yc.DisplayName); login = true; } catch { App.Error("Error logging in."); return; } }