public static void Auth(Queue<string> parameters) { var url = VimeoHook.GetLoginURL( clientId: Constants.GetVimeoAPIKey(), redirect: Constants.GetVimeoRedirectURL()); 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 { vc = VimeoHook.Authorize( authCode: authcode, clientId: Constants.GetVimeoAPIKey(), secret: Constants.GetVimeoAPISecret(), redirect: Constants.GetVimeoRedirectURL() ); Settings.Default.VimeoAccessCode = vc.AccessToken; Settings.Default.Save(); } catch { App.Error("Error logging in."); return; } }
public void SetMetadata(string videoUri, VimeoHook vc) { Action <string> SetStatus = (o) => { if (VimeoHook.VerboseCallback != null) { VimeoHook.VerboseCallback(o); } }; try { SetStatus("Applying Metadata for " + Title); var parameters = new Dictionary <string, string> { { "name", Title }, { "description", Description.Replace("\\n", "\n") }, { "privacy.view", PrivacyView }, { "privacy.embed", PrivacyEmbed }, { "review_link", ReviewLink } }; if (License == "-") { License = ""; } parameters.Add("license", License.Trim()); if (PrivacyView == "password") { parameters.Add("password", Password); } vc.Request(videoUri, parameters, "PATCH", false); SetStatus("Adding Tags for " + Title); foreach (string tag in Tags.Split(',')) { vc.Request(String.Format("{0}/tags/{1}", videoUri, tag), "PUT", false, ""); } if (!Core.IsNullOrWhiteSpace(Album)) { SetStatus("Adding video to album " + Album); string videoRelUri = videoUri.Contains("/video") ? videoUri : "/videos/" + videoUri; vc.Request( string.Format("/me/albums/{0}{1}", Album, videoRelUri), null, "PUT"); } SetStatus("Metadata assignment completed for " + Title); } catch (Exception e) { SetStatus(string.Format("Error applying metadata for {0}: {1}", Title, e.Message)); } }
public void SetMetadata(string videoUri, VimeoHook vc) { Action<string> SetStatus = (o) => { if (VimeoHook.VerboseCallback != null) VimeoHook.VerboseCallback(o); }; try { SetStatus("Applying Metadata for " + Title); var parameters = new Dictionary<string, string>{ {"name",Title}, {"description",Description.Replace("\\n","\n")}, {"privacy.view",PrivacyView}, {"privacy.embed",PrivacyEmbed}, {"review_link",ReviewLink} }; if (License == "-") License = ""; parameters.Add("license", License.Trim()); if (PrivacyView == "password") parameters.Add("password", Password); vc.Request(videoUri, parameters, "PATCH", false); SetStatus("Adding Tags for " + Title); foreach (string tag in Tags.Split(',')) vc.Request(String.Format("{0}/tags/{1}", videoUri, tag), "PUT", false, ""); if (!Core.IsNullOrWhiteSpace(Album)) { SetStatus("Adding video to album " + Album); string videoRelUri = videoUri.Contains("/video") ? videoUri : "/videos/" + videoUri; vc.Request( string.Format("/me/albums/{0}{1}", Album, videoRelUri), null, "PUT"); } SetStatus("Metadata assignment completed for " + Title); } catch (Exception e) { SetStatus(string.Format("Error applying metadata for {0}: {1}", Title, e.Message)); } }
public static VimeoHook Authorize( string authCode, string clientId, string secret, string redirect, string apiRoot = "https://api.vimeo.com") { VimeoHook vc = new VimeoHook(); vc.clientId = clientId; vc.apiRoot = apiRoot; vc.redirect = redirect; vc.AccessJson = GetAccessToken(authCode, clientId, secret, redirect, apiRoot); vc.loadAccessData(); return vc; }
public static VimeoHook Authorize( string authCode, string clientId, string secret, string redirect, string apiRoot = "https://api.vimeo.com") { VimeoHook vc = new VimeoHook(); vc.clientId = clientId; vc.apiRoot = apiRoot; vc.redirect = redirect; vc.AccessJson = GetAccessToken(authCode, clientId, secret, redirect, apiRoot); vc.loadAccessData(); return(vc); }
public static VimeoHook ReAuthorize( string accessToken, string clientId, string redirect = "", string apiRoot = "https://api.vimeo.com") { VimeoHook vc = new VimeoHook(); vc.clientId = clientId; vc.redirect = redirect; vc.AccessToken = accessToken; vc.apiRoot = apiRoot; vc.User = vc.Request("/me", null, "GET"); if (vc.User["error"].Value.Length > 0) { throw new Exception(vc.User["error"]); } return(vc); }
public static bool Login() { try { if (!login) { vc = VimeoHook.ReAuthorize( accessToken: Settings.Default.VimeoAccessCode, clientId: Constants.GetVimeoAPIKey(), secret: Constants.GetVimeoAPISecret(), redirect: Constants.GetVimeoRedirectURL() ); App.Info("Logged in as " + vc.User["name"].ToString()); 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 { vc = VimeoHook.Authorize( authCode: authcode, clientId: Constants.GetVimeoAPIKey(), secret: Constants.GetVimeoAPISecret(), redirect: Constants.GetVimeoRedirectURL() ); Settings.Default.VimeoAccessCode = vc.AccessToken; Settings.Default.Save(); App.Info("Logged in as " + vc.User["name"].ToString()); login = true; } catch { App.Error("Error logging in."); return; } }
public static VimeoHook ReAuthorize( string accessToken, string clientId, string redirect="", string apiRoot = "https://api.vimeo.com") { VimeoHook vc = new VimeoHook(); vc.clientId = clientId; vc.redirect = redirect; vc.AccessToken = accessToken; vc.apiRoot = apiRoot; vc.User = vc.Request("/me", null, "GET"); if (vc.User["error"].Value.Length > 0) throw new Exception(vc.User["error"]); return vc; }