public async void LoadSubscriptions() { if (!ApplicationSetting.GetLocalSetting("google_is_loggedin", false)) { return; } if (_selfSubscriptionVideoCollection != null) { _selfSubscriptionVideoCollection.Clear(); } // Static global variable data to be referenced by the LoadMoreItems function string pagination = null; string firstpagination = null; bool isLoadComplete = false; // Function selfSubscriptionVideoCollection = new IncrementalLoadingCollection <Subscription>((CancellationToken cts, uint count) => { return(Task.Run <ObservableCollection <Subscription> >(async() => { ObservableCollection <Subscription> newcollection = new ObservableCollection <Subscription>(); if (!isLoadComplete) { string uri = string.Format("https://www.googleapis.com/youtube/v3/subscriptions?part={0}&mine={1}&maxResults={2}", "contentDetails%2CsubscriberSnippet%2Csnippet", "true", 50); if (pagination != null) { uri += "&pageToken=" + pagination; } object obj = await YouTubeAuthenticatedAPI.RequestedAuthenticatedAPICall(uri, typeof(SubscriptionResultObject)); if (obj != null) { SubscriptionResultObject deserialize = (SubscriptionResultObject)obj; if (pagination != null && firstpagination == pagination) // Is this the end? { isLoadComplete = true; return newcollection; } else { // Set pagination pagination = deserialize.nextPageToken; if (firstpagination == null) { firstpagination = pagination; // no choice, we might load the first at the end again.. there's no pagination information for the first page } // Add to list of subscription videos foreach (Subscription s in deserialize.items) { newcollection.Add(s); } } } //var videoInfoRequest = YoutubeService.service.Subscriptions.List("contentDetails,id,snippet,subscriberSnippet"); /* videoInfoRequest.RequestParameters.Add("access_token", * new Parameter() * { * Name = "access_token", * DefaultValue = await ApplicationSetting.GetEncryptedLocalStringValueOrDefault("google_access_token", ""), * IsRequired = true, * });*/ //videoInfoRequest.Mine = true; //videoInfoRequest.OauthToken = await ApplicationSetting.GetEncryptedLocalStringValueOrDefault("google_authorization_token", ""); /*if (pagination != null) * { * videoInfoRequest.PageToken = pagination; * } * * try * { * var videoResultResponse = await videoInfoRequest.ExecuteAsync(); * * // Set new pagination * pagination = videoResultResponse.NextPageToken; * if (firstpagination == null) * { * firstpagination = pagination; // no choice, we might load the first at the end again.. there's no pagination information for the first page * } * else if (firstpagination == pagination) * { * isLoadComplete = true; * return newcollection; * } * * foreach (Subscription t in videoResultResponse.Items) * { * newcollection.Add(t); * } * } * catch (Exception exp) * { * Debug.WriteLine(exp.ToString()); * }*/ } return newcollection; })); }); await selfSubscriptionVideoCollection.LoadMoreItemsAsync(10); }
public void LoadComments(string videoid) { if (_commentThreadCollection != null) { _commentThreadCollection.Clear(); } // Static global variable data to be referenced by the LoadMoreItems function string pagination = null; string firstpagination = null; bool isLoadComplete = false; // Function commentCollection = new IncrementalLoadingCollection <CommentThread>((CancellationToken cts, uint count) => { return(Task.Run <ObservableCollection <CommentThread> >(async() => { ObservableCollection <CommentThread> newcollection = new ObservableCollection <CommentThread>(); if (!isLoadComplete) { var videoInfoRequest = YoutubeService.service.CommentThreads.List("snippet,replies"); videoInfoRequest.VideoId = videoid; videoInfoRequest.TextFormat = Google.Apis.YouTube.v3.CommentThreadsResource.ListRequest.TextFormatEnum.PlainText; videoInfoRequest.MaxResults = 50; if (pagination != null) { videoInfoRequest.PageToken = pagination; } try { var videoResultResponse = await videoInfoRequest.ExecuteAsync(); // Set new pagination pagination = videoResultResponse.NextPageToken; if (firstpagination == null) { firstpagination = pagination; // no choice, we might load the first at the end again.. there's no pagination information for the first page } else if (firstpagination == pagination) { isLoadComplete = true; return newcollection; } foreach (CommentThread t in videoResultResponse.Items) { newcollection.Add(t); } } catch (Exception exp) { Debug.WriteLine(exp.ToString()); } } return newcollection; })); }); }
public void LoadRelatedVideo(string related_videoid, string videotitle) { if (_relatedVideoSearchCollection != null) { _relatedVideoSearchCollection.Clear(); } // Static global variable data to be referenced by the LoadMoreItems function string pagination = null; string firstpagination = null; bool isLoadComplete = false; // Function relatedVideoSearchCollection = new IncrementalLoadingCollection <SearchResult>((CancellationToken cts, uint count) => { return(Task.Run <ObservableCollection <SearchResult> >(async() => { ObservableCollection <SearchResult> newcollection = new ObservableCollection <SearchResult>(); if (!isLoadComplete) { var videoInfoRequest = YoutubeService.service.Search.List("snippet"); // videoInfoRequest.Q = videotitle; videoInfoRequest.Type = "video"; videoInfoRequest.RelatedToVideoId = related_videoid; if (pagination != null) { videoInfoRequest.PageToken = pagination; } try { var videoResultResponse = await videoInfoRequest.ExecuteAsync(); // Set new pagination pagination = videoResultResponse.NextPageToken; if (firstpagination == null) { firstpagination = pagination; // no choice, we might load the first at the end again.. there's no pagination information for the first page } else if (firstpagination == pagination) { isLoadComplete = true; return newcollection; } foreach (SearchResult t in videoResultResponse.Items) { newcollection.Add(t); } } catch (Exception exp) { Debug.WriteLine(exp.ToString()); } } return newcollection; })); }); }
public void LoadPlaylist(string channelid, string playlistid, PlaylistType type, string paginationToken) { if (currentPlaylistChannelid != channelid) { _Playlist.Clear(); } if (!_Playlist.ContainsKey(type)) { // Static global variable data to be referenced by the LoadMoreItems function string pagination = paginationToken; string firstpagination = null; bool isLoadComplete = false; // Function IncrementalLoadingCollection <Google.Apis.YouTube.v3.Data.PlaylistItem> currentPlaylistArrayObj = new IncrementalLoadingCollection <Google.Apis.YouTube.v3.Data.PlaylistItem>((CancellationToken cts, uint count) => { return(Task.Run <ObservableCollection <Google.Apis.YouTube.v3.Data.PlaylistItem> >(async() => { ObservableCollection <Google.Apis.YouTube.v3.Data.PlaylistItem> newcollection = new ObservableCollection <Google.Apis.YouTube.v3.Data.PlaylistItem>(); if (!isLoadComplete) { IList <Google.Apis.YouTube.v3.Data.PlaylistItem> collection = null; // Load playlist var videoInfoRequest = YoutubeService.service.PlaylistItems.List("contentDetails,id,status,snippet"); videoInfoRequest.PlaylistId = playlistid; videoInfoRequest.MaxResults = 50; if (pagination != null) { videoInfoRequest.PageToken = pagination; } try { var videoResultResponse = await videoInfoRequest.ExecuteAsync(); // Set new pagination pagination = videoResultResponse.NextPageToken; if (firstpagination == null) { firstpagination = pagination; // no choice, we might load the first at the end again.. there's no pagination information for the first page } else if (firstpagination == pagination) { isLoadComplete = true; return newcollection; } collection = videoResultResponse.Items; } catch { } // Add it to new collection if (collection != null) { foreach (Google.Apis.YouTube.v3.Data.PlaylistItem item in collection) { newcollection.Add(item); } } } Debug.WriteLine("Loaded new items " + new Random().Next(999)); return newcollection; })); }); _Playlist.Add(type, currentPlaylistArrayObj); this.OnPropertyChanged("Playlist_" + type.ToString()); } }