/// <summary> /// Gets a Total object containing a list of Follow objects of type User following the specified user /// </summary> /// <param name="offset">Object offset for pagination. Default is 0.</param> /// <param name="limit">How many users to get at one time. Default is 25. Maximum is 100</param> /// <param name="direction">Creation date sorting direction. Default is Descending.</param> /// <returns>A Total object containing a list of Follow objects of type User</returns> public async Task <Total <List <Follow <User> > > > RetrieveFollowers(int offset = 0, int limit = 25, TwitchConstants.Direction direction = TwitchConstants.Direction.Decending) { Url url = new Url(TwitchConstants.baseUrl).AppendPathSegments("channels", name, "follows"); if (limit <= 100) { url.SetQueryParam("limit", limit); } else { url.SetQueryParam("limit", 100); } url.SetQueryParams(new { offset = offset, direction = TwitchConstants.DirectionToString(direction) }); Uri uri = new Uri(url.ToString()); string responseString; try { responseString = await Twixel.GetWebData(uri, version); } catch (TwitchException ex) { throw new TwixelException(TwitchConstants.twitchAPIErrorString, ex); } JObject responseObject = JObject.Parse(responseString); List <Follow <User> > follows = HelperMethods.LoadUserFollows(responseObject, version); return(HelperMethods.LoadTotal(responseObject, follows, version)); }
/// <summary> /// Get a list of users subscribed to this user. Requires user authorization. Requires Twitch partnership. /// </summary> /// <param name="limit">How many subscriptions to get at one time. Default is 25. Maximum is 100</param> /// <param name="direction">Creation date sorting direction</param> /// <returns>A list of subscriptions</returns> public async Task <List <Subscription> > RetriveSubscribers(int limit, TwitchConstants.Direction direction) { if (authorized && authorizedScopes.Contains(TwitchConstants.Scope.ChannelSubscriptions)) { Uri uri; string url = "https://api.twitch.tv/kraken/channels/" + name + "/subscriptions"; if (limit <= 100) { url += "?limit=" + limit.ToString(); } else { twixel.CreateError("You cannot fetch more than 100 subs at a time"); return(null); } if (direction != TwitchConstants.Direction.None) { url += "&direction=" + TwitchConstants.DirectionToString(direction); } uri = new Uri(url); string responseString = await Twixel.GetWebData(uri, accessToken); if (responseString != "422") { totalSubscribers = (int)JObject.Parse(responseString)["_total"]; nextSubs = new WebUrl((string)JObject.Parse(responseString)["_links"]["next"]); foreach (JObject o in (JArray)JObject.Parse(responseString)["subscriptions"]) { if (!ContainsSubscriber((string)o["user"]["name"])) { subscribedUsers.Add(LoadSubscriber(o)); } } return(subscribedUsers); } else { twixel.CreateError("You aren't partnered so you cannot have subs"); return(null); } } else { if (!authorized) { twixel.CreateError(name + " is not authorized"); } else if (!authorizedScopes.Contains(TwitchConstants.Scope.ChannelSubscriptions)) { twixel.CreateError(name + " has not given channel_subscriptions permissions"); } return(null); } }
/// <summary> /// Get a Total object containing a list of Subscription of type User /// Requires authorization. /// Requires Twitch partnership. /// Requires channel_subscriptions. /// </summary> /// <param name="offset">Object offset for pagination. Default is 0.</param> /// <param name="limit">How many subscriptions to get at one time. Default is 25. Maximum is 100</param> /// <param name="direction">Creation date sorting direction. Default is Ascending.</param> /// <returns>A Total object containing a list of Subscription objects of type User</returns> public async Task <Total <List <Subscription <User> > > > RetriveSubscribers(int offset = 0, int limit = 25, TwitchConstants.Direction direction = TwitchConstants.Direction.Ascending) { TwitchConstants.Scope relevantScope = TwitchConstants.Scope.ChannelSubscriptions; if (authorized && authorizedScopes.Contains(relevantScope) && partnered) { Url url = new Url(TwitchConstants.baseUrl).AppendPathSegments("channels", name, "subscriptions"); if (limit <= 100) { url.SetQueryParam("limit", limit); } else { url.SetQueryParam("limit", 100); } url.SetQueryParams(new { offset = offset, direction = TwitchConstants.DirectionToString(direction) }); Uri uri = new Uri(url.ToString()); string responseString; try { responseString = await Twixel.GetWebData(uri, accessToken, version); } catch (TwitchException ex) { throw new TwixelException(TwitchConstants.twitchAPIErrorString, ex); } JObject responseObject = JObject.Parse(responseString); List <Subscription <User> > subs = HelperMethods.LoadUserSubscriptions(JObject.Parse(responseString), version); return(HelperMethods.LoadTotal(responseObject, subs, version)); } else { if (!authorized) { throw new TwixelException(NotAuthedError()); } else if (!authorizedScopes.Contains(relevantScope)) { throw new TwixelException(MissingPermissionError(relevantScope)); } else if (!partnered) { throw new TwixelException(NotPartneredError()); } else { throw new TwixelException(TwitchConstants.unknownErrorString); } } }