Coder Social home page Coder Social logo

Comments (4)

geekingfrog avatar geekingfrog commented on August 15, 2024 1

Oh right. Might be worth mentioning this in the doc of get_users, or/and GetUsersRequest.

from twitch_api.

Emilgardis avatar Emilgardis commented on August 15, 2024

the url we call for

get_users::GetUsersRequest::builder()
    .id(vec![])
    .login(vec![])
    .build();

would be https://api.twitch.tv/helix/users? (check with request.get_uri())

calling this is special-cased by twitch, where it returns the current user. For me for example

image

I'm not sure I understand the issue here. Where is the error?

from twitch_api.

geekingfrog avatar geekingfrog commented on August 15, 2024

This is interesting, it seems the behavior is different in the browser. Probably because you have some form of cookie?
Here's an example exhibiting the problem:

use twitch_api2::{twitch_oauth2::AppAccessToken, TwitchClient};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client_id = std::env::var("TWITCH_CLIENT_ID").unwrap().into();
    let client_secret = std::env::var("TWITCH_CLIENT_SECRET").unwrap().into();
    let client: TwitchClient<reqwest::Client> = TwitchClient::default();
    let token = AppAccessToken::get_app_access_token(&client, client_id, client_secret, vec![])
        .await
        .unwrap();

    let req = twitch_api2::helix::users::get_users::GetUsersRequest::builder()
        .id(vec![])
        .login(vec![])
        .build();

    let resp = client.helix.req_get(req, &token).await;
    dbg!(&resp);
    resp.expect("valid response");

    Ok(())
}

This gives:

[src/testtwitch.rs:18] &resp = Err(
    HelixRequestGetError(
        Error {
            error: "Bad Request",
            status: 400,
            message: "Must provide an ID, Login or OAuth Token.",
            uri: https://api.twitch.tv/helix/users?,
        },
    ),
)
thread 'main' panicked at 'valid response: HelixRequestGetError(Error { error: "Bad Request", status: 400, message: "Must provide an ID, Login or OAuth Token.", uri: https://api.twitch.tv/helix/users? })', src/testtwitch.rs:19:10

I'm using tokio version "1.0.1" and twitch_api version 0.6.0-rc.3

from twitch_api.

Emilgardis avatar Emilgardis commented on August 15, 2024

Aha, no default user associated with apptokens so twitch throws an error on empty query. There are no differences with using a browser, I jus have an addon setting the correct headers, using an user token.

I dont think it's possible or usable for twitch_api2 to catch this kind of error without speaking to twitch.

from twitch_api.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.