public void CreateTemplate() { DocumentsService service = new DocumentsService(applicationName); DocumentEntry entry = new DocumentEntry(); // Set the document title entry.Title.Text = spreadsheetName; entry.IsSpreadsheet = true; // Set the media source entry.MediaSource = new MediaFileSource(GetStreamWithTemplate(), applicationName, "text/csv"); // Define the resumable upload link Uri createUploadUrl = new Uri("https://docs.google.com/feeds/upload/create-session/default/private/full"); AtomLink link = new AtomLink(createUploadUrl.AbsoluteUri); link.Rel = ResumableUploader.CreateMediaRelation; entry.Links.Add(link); // Set the service to be used to parse the returned entry entry.Service = service; // Instantiate the ResumableUploader component. ResumableUploader uploader = new ResumableUploader(); // Start the upload process uploader.Insert(new ClientLoginAuthenticator(applicationName, ServiceNames.Documents, userName, password), entry); }
public void Execute(string title, string description, string keywords, string category, ID item, string handle) { master = Factory.GetDatabase("master"); Item settings = master.GetItem(Data.YouTubeSettingsID); this.handleID = handle; if (settings == null) { Log.Error("YouTube Settings not found!", this); return; } else { devKey = settings.Fields[Data.DevKeyFieldID].Value; clientID = settings.Fields[Data.ClientIDFieldID].Value; username = settings.Fields[Data.UserNameFieldID].Value; password = settings.Fields[Data.PasswordFieldID].Value; EnsureRU(); UserState u = new UserState(); u.RetryCounter = 0; Authenticator youTubeAuthenticator = new ClientLoginAuthenticator("SitecoreYouTubeUploader", ServiceNames.YouTube, username, password); youTubeAuthenticator.DeveloperKey = devKey; YouTubeEntry newVideo = new YouTubeEntry(); newVideo.Media = new Google.GData.YouTube.MediaGroup(); newVideo.Media.Title = new MediaTitle(title); newVideo.Media.Keywords = new MediaKeywords(keywords); newVideo.Media.Description = new MediaDescription(description); newVideo.Media.Categories.Add(new MediaCategory(category, YouTubeNameTable.CategorySchema)); MediaItem media = master.GetItem(item); Stream mediaStream = media.GetMediaStream(); MemoryStream uploadStream = CopyStream.CopyMediaItemStream(mediaStream); newVideo.MediaSource = new MediaFileSource(uploadStream, media.DisplayName, media.MimeType); AtomLink link = new AtomLink("http://uploads.gdata.youtube.com/resumable/feeds/api/users/default/uploads"); link.Rel = ResumableUploader.CreateMediaRelation; newVideo.Links.Add(link); // Async Method // uploader.InsertAsync(youTubeAuthenticator, newVideo, u); try { var response = uploader.Insert(youTubeAuthenticator, newVideo); string id = response.ResponseUri.PathAndQuery; id = id.Substring(id.IndexOf("/uploads/") + 9, id.Length - id.IndexOf("/uploads/") - 9); Sitecore.Context.Job.Status.Messages.Add(id); Sitecore.Context.Job.Status.Failed = false; } catch (WebException ex) { Sitecore.Context.Job.Status.Messages.Add(ex.StackTrace); Sitecore.Context.Job.Status.Failed = true; Log.Error("Youtube Video upload failed", ex, this); } } }