Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Potential fix to query multiple channels #409

Closed
wants to merge 0 commits into from

Conversation

AWAS666
Copy link

@AWAS666 AWAS666 commented Nov 21, 2024

This might be wrong, I did a quick and dirty example in github.dev ;)
But should get the idea accross what's needed for #408

Also there might be other endpoints here with the same issue

@Hampo
Copy link
Contributor

Hampo commented Nov 21, 2024

Thanks for your contribution, unfortunately that code won't work as you're encapsulating getParams inside for the foreach loop. For a better idea on how best to implement this, look at something like GetVIPsAsync's userIds in the same file.

Additionally, for backwards compatibility, it might be worth adding something like:

public Task<GetChannelInformationResponse> GetChannelInformationAsync(string broadcasterId, string accessToken = null) => GetChannelInformationAsync(new List<string>() { broadcasterId }, accessToken);

Copy link
Member

@Mahsaap Mahsaap left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me but please target Dev branch.
And the getparams like Hampo stated, needs to be outside the loop

@Hampo
Copy link
Contributor

Hampo commented Nov 21, 2024

Not tested, but something like:

public Task<GetChannelInformationResponse> GetChannelInformationAsync(List<string> broadcasterIds, string accessToken = null)
{
    if (broadcasterIds.Count == 0 || broadcasterIds.Count > 100)
        throw new BadParameterException("boardcasterIds must contain between 1 and 100 broadcasterIds.");

    var getParams = broadcasterIds.Select(broadcasterId => new KeyValuePair<string, string>("broadcaster_id", broadcasterId)).ToList();

    return TwitchGetGenericAsync<GetChannelInformationResponse>("/channels", ApiVersion.Helix, getParams, accessToken);
}
  • Changed .Count() from the Linq function to the List's property Count.
  • Used Linq to generate the getParams List from the broadcasterIds parameter.

@AWAS666 AWAS666 changed the base branch from master to dev November 21, 2024 20:42
@AWAS666 AWAS666 closed this Nov 21, 2024
@AWAS666
Copy link
Author

AWAS666 commented Nov 21, 2024

well that wasn't the brightest idea, I'll just create a new pr so this isn't a mess :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants