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.2"}]
end
Ensure Twittex is started before your application:
def application do
[applications: [:twittex]]
end
Add your app’s consumer_key
and consumer_secret
to config/config.exs
:
config :twittex,
consumer_key: "3rJOl1ODzm9yZy63FACdg",
consumer_secret: "5jPoQ5kQvMJFDYRNE8bQ4rHuds4xJqhvgNJM4awaE8"
Authentication
Twittex supports both Application-only and user-credentials (xAuth) authentication methods.
You should read the Twitter OAuth documentation for more details.
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 have the context of an authenticated user and access restricted endpoints and features you cannot access with the former method, you will have to use the xAuth extension.
To do so, simply add your credentials to your application config file:
config :twittex,
# consumer key and secret
username: "myusername",
password: "mypassword"
Usage
Returns a collection of relevant Tweets matching #myelixirstatus
:
iex> Twittex.Client.search "#myelixirstatus"
{:ok, %{}}
Same a the previous example but returns the last 50 Tweets (instead of 15):
iex> Twittex.Client.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.Client.home_timeline
{:ok, %{}}
Returns a stream that consume Tweets from public data flowing through Twitter:
iex> {:ok, stream} = Twittex.Client.stream "#myelixirstatus"
{:ok, stream}
iex> Enum.each stream, &IO.inspect/1