egg-mode-rs / egg-mode

a twitter api crate for rust
https://crates.io/crates/egg-mode
Mozilla Public License 2.0
371 stars 65 forks source link

Getting 401 unauthorized when requesting stream filter #109

Open egithinji opened 4 years ago

egithinji commented 4 years ago

I'm using the example here: https://github.com/egg-mode-rs/egg-mode/blob/master/examples/stream_filter.rs Just that I'm entering my token differently in the start function. The same token works fine when fetching tweets using egg_mode::tweet::user_timeline. But when fetching the stream I get 401 unauthorized.

Am I doing something wrong?

`#[tokio::main] async fn main() {

let con_token = egg_mode::KeyPair::new(CONSUMER_KEY, CONSUMER_SECRET);

println!("Live streaming tweets...");

println!("Ctrl-C to quit\n");

let stream = egg_mode::stream::filter()
    .track(&["rustlang"])
    .start(&Token::Bearer(BEARERTOKEN.to_string()))
    .try_for_each(|m| {
        if let StreamMessage::Tweet(tweet) = m {
            println!("{}\n{}",tweet.created_at,tweet.text);
       } else {
            println!("{:?}",m);
        }
        futures::future::ok(())
    });
if let Err(e) = stream.await {
    println!("Stream error: {}", e);
    println!("Disconnected")
}

}`

egithinji commented 4 years ago

It works when I pass a Token with the Access variant instead of the Bearer variant.

Kerollmops commented 2 years ago

I confirm that the access token (Token::Access) works but neither the Token::Bearer variant nor the token output from the auth::bearer_token that is derived from a KeyPair. In short, it seems that the API changed on the Twitter side and that bearers do not work anymore.