exfacebook v0.1.1 Exfacebook

Exfacebook implements Graph Api:

  • Exfacebook.Api - graph calls using access token to Facebook Graph API, depends on respnse it returns decoded to JSON values.

  • Exfacebook.Config - specify api_version and http requests for hackney.

Configuration example(optional variables):

config :exfacebook,
  api_version: "v2.6",
  http_options: [recv_timeout: :infinity],
  id: "your_app_id_optional",
  secret: "your_app_secret_optiona"

How to use API?

Examples:

  • start_link - if you want to have worker you can start Exfacebook GenServer and use pid as entry param for API methods:
  {:ok, pid} = Exfacebook.start_link
  • get_object - get user or page related attributes, in case if you decide to use specific params for Facebook API like fields
  {:ok, %{"id" => id, "picture" => picture}} = Exfacebook.get_object(
     pid, :me, %{access_token: "access-token", fields: "id, picture"})
  • get_connections - get collection related items and attributes(feed or home or friends):
    {:ok, %{"data" => collection}} = response = Exfacebook.get_connections(
       pid, :feed, %{fields: "id, name", access_token: "access-token"})
  • next_page/prev_page - take next or prev collections using response from get_connections:
    response = Exfacebook.get_connections(pid, :feed,
       %{fields: "id, name", access_token: "access-token"})
    response2 = Exfacebook.next_page(pid, response)
    response3 = Exfacebook.next_page(pid, response2)
    response4 = Exfacebook.prev_page(pid, response3)
  • put_connections - update actions in facebook, example creates the new message in feed:
    Exfacebook.put_connections(:me, :feed,
       %{access_token: "access-token"}, %{message: "hello"})

Summary

Functions

Passing prepared params for batch processing using Facebook API

You can use delete_object and delete_connections passing pid or directly from Api module. In case of missing permissions to delete items you will error object as response

Fetches an access token with extended expiration time (ignoring expiration and other info)

Fetches an access_token with extended expiration time, along with any other information provided by Facebook. See https://developers.facebook.com/docs/offline-access-deprecation/#extend_token (search for fb_exchange_token)

API for easy accessing basic Facebook API functions like get avatar image, put comment, image, video or make wall post

Realtime updates using subscriptions API

Make likes or delete this action for specific post

Functions

batch(callback)
batch(params, callback)

Passing prepared params for batch processing using Facebook API.

Params are coming like normal requests encoded to JSON and then Facebook emulate requests on their side:

delete_connections(pid, id, name, params)
delete_connections(api, pid, id, name, params)
delete_like(pid, id, params)
delete_like(api, pid, id, params)
delete_object(pid, id, params)

You can use delete_object and delete_connections passing pid or directly from Api module. In case of missing permissions to delete items you will error object as response.

Examples:

  • delete_connections - delete item from connections
  {:ok, response} = Exfacebook.Api.delete_connections(:me, :feed, %{ ... })
  • delete_object - delete item from Facebook data
  {:ok, response} = Exfacebook.Api.delete_object("item-id")
delete_object(api, pid, id, params)
exchange_access_token(pid, access_token)

Fetches an access token with extended expiration time (ignoring expiration and other info).

exchange_access_token_info(pid, access_token)

Fetches an access_token with extended expiration time, along with any other information provided by Facebook. See https://developers.facebook.com/docs/offline-access-deprecation/#extend_token (search for fb_exchange_token).

get_connections(pid, id, name, params)
get_connections(api, pid, id, name, params)
get_object(pid, id, params)
get_object(api, pid, id, params)
get_picture_data(pid, id, params)

API for easy accessing basic Facebook API functions like get avatar image, put comment, image, video or make wall post.

Examples:

  • put_picture - upload new photo to id feed
  {:ok, response} = Exfacebook.Api.put_picture(:me, params, "/path/file.jpg")
  {:ok, response} = Exfacebook.Api.put_picture(:me, params, {:url, "http://www.example.com/file.jpg"})
  • put_video - upload new video to id feed
  {:ok, response} = Exfacebook.Api.put_video(:me, params, "/path/file.mp4")
  {:ok, response} = Exfacebook.Api.put_video(:me, params, {:url, "http://www.example.com/file.mp4"})
get_picture_data(api, pid, id, params)
list_subscriptions(pid, params)

Realtime updates using subscriptions API

Examples:

  • list_subscriptions - returns list of subscriptions
  params = %{fields: "id,name"}

  {:ok, %{
    "data" => [
      %{"active" => true,
        "callback_url" => "https://example.com/client/subscriptions",
        "fields" => ["feed", "friends", "music"],
        "object" => "user"}]
    }
  } = Exfacebook.Api.list_subscriptions(params)
  • subscribe - subscribe to real time updates for object, fields should contains object to watch for updates(“feed, friends”).
  Exfacebook.Api.subscribe("id-1",
    "friends, feed", "http://www.example.com/facebook/updates",
    "token-123")
  • unsubscribe - unsubscribe object from real time updates.
  Exfacebook.Api.unsubscribe("id-1")
next_page(pid, response)
next_page(api, pid, response)
prev_page(pid, response)
prev_page(api, pid, response)
put_comment(pid, id, params, message)
put_comment(api, pid, id, params, message)
put_connections(pid, id, name, params, body)
put_connections(api, pid, id, name, params, body)
put_like(pid, id, params)

Make likes or delete this action for specific post:

Examples:

  • put_like - like object, params should include access_token
  {:ok, response} = Exfacebook.Api.put_like(:me, params)
  • delete_like - unlike object, params should include access_token
  {:ok, response} = Exfacebook.Api.delete_like(:me, params)
put_like(api, pid, id, params)
put_picture(pid, id, params, file)
put_video(pid, id, params, file)
put_wall_post(pid, id, message, params, attachment)
put_wall_post(api, pid, id, message, params, attachment)
start_link(options \\ [])
subscribe(pid, object, fields, callback_url, verify_token)
unsubscribe(pid, object)