public AccessToken RetrieveToken(string clientId, string clientSecret) { var salt = string.Format(CultureInfo.CurrentCulture, "Basic {0}", string.Format(CultureInfo.CurrentCulture, "{0}:{1}", clientId, clientSecret).ToBase64String()); var context = new RestContext(Constants.BrightCoveOauthService); var parameters = new List <Parameter> { new Parameter { Name = "grant_type", Type = ParameterType.GetOrPost, Value = "client_credentials" } }; var request = context.CreateRequest <string, AccessToken>(EntityActionType.Create, "access_token", null, parameters) .AddAuthorization(salt); var response = context.GetResponse <AccessToken>(request); return(response.Data); }
protected override object UploadInternal(NameValueCollection parameters, byte[] fileBytes, Item accountItem) { try { var fileName = this.GetFileName(parameters); string name = Path.GetFileNameWithoutExtension(fileName); var videoToUpload = new VideoToUpload { Name = name, ShortDescription = name, StartDate = ((long)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds).ToString(CultureInfo.InvariantCulture) }; var authenticator = new BrightcoveAthenticator(accountItem); var updateData = new PostData("create_video", authenticator, "video", videoToUpload); var context = new RestContext(Constants.SitecoreRestSharpService, authenticator); IRestRequest restRequest = context.CreateRequest <PostData, ResultData <string> >(EntityActionType.Create, "update_data", updateData); restRequest.AddFile(name, fileBytes, fileName); restRequest.Timeout = 86400000; // 24h var data = context.GetResponse <ResultData <string> >(restRequest).Data; if (data != null && !string.IsNullOrEmpty(data.Result)) { return(new Video { Id = data.Result, Name = name }); } return(null); } catch (Exception ex) { LogHelper.Error("Brightcove Upload is failed", this, ex); return(null); } }