# Twittex
[](https://travis-ci.org/almightycouch/twittex)
[](https://hex.pm/packages/twittex)
[](http://hexdocs.pm/twittex)
[](https://raw.githubusercontent.com/almightycouch/twittex/master/LICENSE)
[](http://github.com/almightycouch/twittex/issues)

Twitter client library for Elixir.
It provides support for both *OAuth1.0* and *OAuth2.0* authentication protocols.
## Documentation
See the [online documentation](https://hexdocs.pm/twittex/) for more information.
## Installation
Add `:twittex` to your list of dependencies in `mix.exs`:
```elixir
def deps do
[{:twittex, "~> 0.3"}]
end
```
Add your app's `consumer_key` and `consumer_secret` to `config/config.exs`:
```elixir
config :twittex,
consumer_key: "xxxxxx",
consumer_secret: "xxxxxx"
```
## Usage
Returns a collection of relevant Tweets matching `#myelixirstatus`:
```elixir
iex> Twittex.search "#myelixirstatus"
{:ok, %{...}}
```
Same a the previous example but returns the last 50 Tweets (instead of 15):
```elixir
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:
```elixir
iex> Twittex.home_timeline
{:ok, %{...}}
```
Returns a stream that consume Tweets from public data flowing through Twitter:
```elixir
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](https://dev.twitter.com/oauth/overview/application-owner-access-tokens).
To do so, simply add your access token to your application config file:
```elixir
config :twittex,
token: "xxxxxx",
token_secret: "xxxxxx"
```