通过Twitch API将用户下载到我的抽搐中

发布于 2025-01-24 09:37:56 字数 1168 浏览 2 评论 0 原文

我正在尝试获取通过Twitch API订阅Twitch频道的用户列表,我已经设置了获取访问令牌的请求,然后我拨打api/helix/subpcriptions/caster in access occess token in occess token订户列表,但是我一直遇到无法获得成功请求的同一问题。

请求未经授权的状态代码失败

var options = new RestClientOptions("https://id.twitch.tv/oauth2/token")
{
    ThrowOnAnyError = true,
    Timeout = 1000
};

var client = new RestClient(options);

var request = new RestRequest()
    .AddQueryParameter("grant_type", "client_credentials")
    .AddQueryParameter("client_id", clientId)
    .AddQueryParameter("client_secret", clientSecret);

var response = await client.PostAsync(request);
var result = JsonConvert.DeserializeObject<OauthToken>(response.Content);

var userOptions = new RestClientOptions("https://api.twitch.tv/helix/subscriptions");

var clientR2 = new RestClient(userOptions);

var requestR2 = new RestRequest()
    .AddHeader("Authorization", "Bearer " + result.access_token)
    .AddHeader("Client-Id", clientId)
    .AddQueryParameter("broadcaster_id", broadcasterId);

var responseR2 = await clientR2.GetAsync(requestR2);

我不确定是否可以使用,我已经介绍了大多数Twitch API文档,并且我有类似的设置与仅获得“用户”,但是即使使用类似的参数,订阅似乎也无法正常工作。

I am trying to get a list of users who are subscribed to a twitch channel through the twitch API, I have setup the request to get the access token and then I am calling the API /helix/subscriptions/ passing in the access token to get the list of subscribers, however I keep running into the same issue where I can't get a successful request.

Request failed with status code Unauthorized

var options = new RestClientOptions("https://id.twitch.tv/oauth2/token")
{
    ThrowOnAnyError = true,
    Timeout = 1000
};

var client = new RestClient(options);

var request = new RestRequest()
    .AddQueryParameter("grant_type", "client_credentials")
    .AddQueryParameter("client_id", clientId)
    .AddQueryParameter("client_secret", clientSecret);

var response = await client.PostAsync(request);
var result = JsonConvert.DeserializeObject<OauthToken>(response.Content);

var userOptions = new RestClientOptions("https://api.twitch.tv/helix/subscriptions");

var clientR2 = new RestClient(userOptions);

var requestR2 = new RestRequest()
    .AddHeader("Authorization", "Bearer " + result.access_token)
    .AddHeader("Client-Id", clientId)
    .AddQueryParameter("broadcaster_id", broadcasterId);

var responseR2 = await clientR2.GetAsync(requestR2);

I am not sure not if this is possible, I have gone over most of the twitch API documents and I've got a similar setup working with just getting "users", but subscriptions seems to not be working even with similar parameters.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不必了 2025-01-31 09:37:56

您正在使用错误的OAuth流。

您需要一个代表用户的令牌, client_credentials 广义地说不代表用户,而是“服务器”。

因此,使用令牌,您无权阅读 broadcasterid 订阅。因此,未经授权的状态代码失败了403/请求

在此处阅读更多有关官方文档:

您需要一个response_type code> code> code token not /代码>

You are using the wrong oAuth flow.

You need a token that representes a user, client_credentials broadly speaking doesn't represent a user but a "server".

So with your token you do not have permission to read broadcasterId subscriptions. Hence the 403/Request failed with status code Unauthorized

Read more on the official documentation here: https://dev.twitch.tv/docs/authentication#user-access-tokens

You need a response_type code or token not client_credentials

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文