Facebook.Stream (facebook_updated v0.24.2) View Source

Provides stream functionalities for the Facebook Graph API paginated responses

See: https://developers.facebook.com/docs/graph-api/using-graph-api/#reading

Link to this section Summary

Functions

Build a stream resource from a facebook paginated response with a custom define error handler and a maximum of retries

Link to this section Types

Specs

error() :: any()

Specs

retry() :: pos_integer()

Link to this section Functions

Link to this function

new(arg, error_handler \\ fn _error, _retry -> Process.sleep(1000) end, max_retries \\ 3)

View Source

Specs

new(Map.t(), (error(), retry() -> any()), pos_integer()) :: Enumerable.t()

Build a stream resource from a facebook paginated response with a custom define error handler and a maximum of retries

The user defined error handler can be used to log errors, delay next retry, raise an exception, etc. The default error handler sleeps 1 second between retries.

Examples

iex> stream = Facebook.page_feed(:feed, "CocaColaMx", "<Your Token>", "id,name") |> Facebook.Stream.new
iex> stream |> Stream.filter(fn(name) -> name == "Coca Cola" end) |> Stream.take(100) |> Enum.to_list

Custom error handler with linear backoff

iex> feed = Facebook.page_feed(:feed, "CocaColaMx", "<Your Token>", 25, "id,name")
iex> stream = Facebook.Stream.new(feed, fn(error, retry) -> Process.sleep(retry*500) end)
iex> stream |> Stream.filter(fn(name) -> name == "Coca Cola" end) |> Stream.take(100) |> Enum.to_list