twittex
twittex copied to clipboard
Twitter client library for Elixir.
Twittex
Twitter client library for Elixir.
It provides support for both OAuth1.0 and OAuth2.0 authentication protocols.
Documentation
See the online documentation for more information.
Installation
Add :twittex
to your list of dependencies in mix.exs
:
def deps do
[{:twittex, "~> 0.3"}]
end
Add your app's consumer_key
and consumer_secret
to config/config.exs
:
config :twittex,
consumer_key: "xxxxxx",
consumer_secret: "xxxxxx"
Usage
Returns a collection of relevant Tweets matching #myelixirstatus
:
iex> Twittex.search "#myelixirstatus"
{:ok, %{...}}
Same a the previous example but returns the last 50 Tweets (instead of 15):
iex> Twittex.search "#myelixirstatus", count: 50
{:ok, %{...}}
Returns a collection of the most recent Tweets and retweets posted by the authenticating user and the users they follow:
iex> Twittex.home_timeline
{:ok, %{...}}
Returns a stream that consume Tweets from public data flowing through Twitter:
iex> {:ok, stream} = Twittex.stream "#myelixirstatus"
{:ok, #Function<51.48026477/2 in Stream.resource/3>}
iex> Enum.each stream, &IO.inspect/1
:ok
Authentication
Twittex supports both application-only and owner-token authentication methods.
Using application-only authentication, your app will be able to, for example:
- Pull user timelines;
- Access friends and followers of any account;
- Access lists resources;
- Search in tweets;
- Retrieve any user information;
And it won’t be able to:
- Post tweets or other resources;
- Connect in Streaming endpoints;
- Search for users;
- Use any geo endpoint;
- Access DMs or account credentials;
In order to access restricted endpoints and features you cannot access with the former method, you will have to use authenticate with your owner-token from dev.twitter.com.
To do so, simply add your access token to your application config file:
config :twittex,
token: "xxxxxx",
token_secret: "xxxxxx"