Coder Social home page Coder Social logo

jkarns275 / twitter-rs Goto Github PK

View Code? Open in Web Editor NEW

This project forked from egg-mode-rs/egg-mode

0.0 2.0 0.0 504 KB

egg-mode, a twitter api crate for rust

Home Page: https://crates.io/crates/egg-mode

License: Mozilla Public License 2.0

Rust 100.00%

twitter-rs's Introduction

egg-mode

another twitter library for rust Build Status Build status

v0.10.0 Documentation | (Pending release documentation)

This is a library for interacting with Twitter from Rust. You can see how much of the Public API is available in the file TODO.md. In addition to eventually implementing the entire Public API, an explicit goal for egg-mode is to make it as easy as possible for a client of this library to interact with the Twitter API. Parts of this library are added as a convenience on top of the API mechanisms; for example, cursored lists of users and tweets can be used as an iterator in addition to being able to manually load a page at a time.

Compatibility note: egg-mode is tested to run on Rust 1.17.0 and later. On Windows, both the -msvc and -gnu environments are tested.

To start using this library, put the following into your Cargo.toml:

[dependencies]
egg-mode = "0.10.0"

...and the following in your lib.rs or main.rs:

extern crate egg_mode;

See available methods and tips to get started in the Documentation.

To authenticate a user and request an access token:

let con_token = egg_mode::KeyPair::new("consumer key", "consumer secret");
let request_token = egg_mode::request_token(&con_token, "oob").unwrap();
let auth_url = egg_mode::authorize_url(&request_token);

// give auth_url to the user, they can sign in to Twitter and accept your app's permissions.
// they'll receive a PIN in return, they need to give this to your application

let (token, user_id, screen_name) =
    egg_mode::access_token(con_token, &request_token, pin).unwrap();

As the last line shows, this also returns the User ID and username of the user that authenticated with your application. With this access token, all of the other Twitter functions become available.

With this token in hand, you can get a user's profile information like this:

let rustlang = egg_mode::user::show("rustlang", &token).unwrap();

println!("{} (@{})", rustlang.name, rustlang.screen_name);

If you'd like to see the examples and implementation for the version currently on crates.io, check the v0.10.0 tag.

For more examples of how to use this library, check the files in the examples folder. The authentication code for most of them is in examples/common/mod.rs, though that's also mostly wrapped up in code to write the access token to disk and load it back in. examples/bearer.rs is an example of using application-only authentication to get a Bearer token and use it to load a user's posts. Other examples showcase a handful of actions from their related module. To run any of the examples for yourself, see the notes in examples/common/mod.rs.

If you've found egg-mode useful, or just want to communicate your first impressions of it, please track me down on Twitter and let me know!

License

This library is licensed under the Mozilla Public License, version 2.0. See the LICENSE file for details.

twitter-rs's People

Watchers

 avatar  avatar

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.