facebook v0.16.0 Facebook

Provides API wrappers for the Facebook Graph API

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

Summary

Functions

Exchange an authorization code for an access token

Get the count of fans for the provided page_id

Exchange a short lived access token for a long lived one

Basic user infos of the logged in user (specified by the access_token)

Likes of the currently logged in user (specified by the access_token)

Gets the number of elements that a scope has in a given object

Gets the number of reactions that an object has

Get all the object reactions with single request

Basic page information for the provided page_id

Get page information for the specified fields for the provided page_id

Gets the feed of posts (including status updates) and links published by this page, or by others on this page

Retrieves a list of granted permissions

A Picture for a Facebook User

Publish to a feed. Author (user or page) is determined from the supplied token

Publish media to a feed. Author (user or page) is determined from the supplied token

If you want to use an appsecret proof, pass it into set_appsecret

Start hook

Supervisor start

Get all test users for an app

Types

fields :: list
limit :: number
num_resp :: {:ok, number} | {:error, Map.t}
react_type :: atom
reaction :: :reaction
resp :: {:ok, Map.t} | {:error, Map.t}
scope :: atom | String.t
using_appsecret :: boolean

Functions

access_token(client_id, client_secret, redirect_uri, code)

Specs

access_token(String.t, String.t, String.t, String.t) :: resp

Exchange an authorization code for an access token

Examples

iex> Facebook.access_token("client_id", "client_secret", "redirect_uri", "code")
{:ok, %{
  "access_token" => access_token,
  "expires_in" => 5183976,
  "token_type" => "bearer"
}}

See: https://developers.facebook.com/docs/facebook-login/manually-build-a-login-flow#confirm

fan_count(page_id, access_token)

Specs

fan_count(page_id :: integer | String.t, access_token) :: integer

Get the count of fans for the provided page_id

Example

iex> Facebook.fan_count("CocaColaMx", "<Access Token>")
{:ok, %{"fan_count" => fan_count, "id" => id}}

See: https://developers.facebook.com/docs/graph-api/reference/page/

long_lived_access_token(client_id, client_secret, access_token)

Specs

long_lived_access_token(String.t, String.t, String.t) :: resp

Exchange a short lived access token for a long lived one

Examples

iex> Facebook.long_lived_access_token("client_id", "client_secret", "access_token")
{:ok, %{
  "access_token" => access_token,
  "expires_in" => 5183976,
  "token_type" => "bearer"
}}

See: https://developers.facebook.com/docs/facebook-login/access-tokens/expiration-and-extension

me(fields, access_token)

Specs

me(fields :: String.t, access_token) :: resp
me(fields, access_token) :: resp

Basic user infos of the logged in user (specified by the access_token).

Example

iex> Facebook.me([fields: "id,first_name"], "<Access Token>")
{:ok, %{"first_name" => "...", "id" => "..."}}

See: https://developers.facebook.com/docs/graph-api/reference/user/

my_likes(access_token)

Specs

my_likes(access_token) :: resp

Likes of the currently logged in user (specified by the access_token)

Example

iex> Facebook.my_likes("<Access Token>")
{:ok, %{"data" => [...]}}

See: https://developers.facebook.com/docs/graph-api/reference/user/likes

object_count(scope, object_id, access_token)

Specs

object_count(scope, object_id, access_token) :: num_resp

Gets the number of elements that a scope has in a given object.

An object stands for: post, comment, link, status update, photo.

If you want to get the likes of a page, please see fan_count.

Expected scopes:

  • :likes
  • :comments

Example

iex> Facebook.object_count(:likes, "1326382730725053_1326476257382367", "<Access Token>")
{:ok, 10}
iex> Facebook.object_count(:comments, "1326382730725053_1326476257382367", "<Access Token>")
{:ok, 5}

See: https://developers.facebook.com/docs/graph-api/reference/object/likes See: https://developers.facebook.com/docs/graph-api/reference/object/comments

object_count(atom, react_type, object_id, access_token)

Specs

Gets the number of reactions that an object has.

Expected type of reactions:

  • :haha
  • :wow
  • :thankful
  • :sad
  • :angry
  • :love
  • :none

Examples

iex> Facebook.object_count(
  :reaction,
  :wow,
  "769860109692136_1173416799336463",
  "<Access Token>"
)
{:ok, 100}
iex> Facebook.object_count(
  :reaction,
  :haha,
  "769860109692136_1173416799336463",
  "<Access Token>"
)
{:ok, 100}
iex> Facebook.object_count(
  :reaction,
  :thankful,
  "769860109692136_1173416799336463",
  "<Access Token>"
)
{:ok, 100}
object_count_all(object_id, access_token)

Specs

object_count_all(object_id :: String.t, access_token) :: resp

Get all the object reactions with single request.

Examples

iex> Facebook.object_count_all("769860109692136_1173416799336463", "<Access Token>")
{:ok, %{"angry" => 0, "haha" => 1, "like" => 0, "love" => 0, "sad" => 0, "wow" => 0}}
page(page_id, access_token)

Specs

page(page_id :: integer | String.t, access_token) :: resp

Basic page information for the provided page_id

Example

iex> Facebook.page("CocaColaMx", "<Access Token>")
{:ok, %{"id" => id, "name" => name}}

See: https://developers.facebook.com/docs/graph-api/reference/page

page(page_id, access_token, fields)

Specs

page(page_id :: integer | String.t, access_token, fields) :: resp

Get page information for the specified fields for the provided page_id

Example

iex> Facebook.page("CocaColaMx", "<Access Token>", "id")
{:ok, %{"id" => id}

See: https://developers.facebook.com/docs/graph-api/reference/page

page_feed(scope, page_id, access_token, limit \\ 25, fields \\ "")

Specs

Gets the feed of posts (including status updates) and links published by this page, or by others on this page.

This function can retrieve the four types:

  • feed
  • posts
  • promotable posts (Admin permission needed)
  • tagged posts

A scope must be provided. It is a string, which represents the type of feed.

A limit of posts may be given. The maximum number that must be provided is 100.

Examples

iex> Facebook.page_feed(:posts, "CocaColaMx", "<Access Token>")
iex> Facebook.page_feed(:tagged, "CocaColaMx", "<Access Token>", 55)
iex> Facebook.page_feed(:promotable_posts, "CocaColaMx", "<Access Token>")
iex> Facebook.page_feed(:feed, "CocaColaMx", "<Access Token>", 55, "id,name")
{:ok, %{"data" => [...]}}

See: https://developers.facebook.com/docs/graph-api/reference/page/feed

permissions(user_id, access_token)

Specs

permissions(user_id :: integer | String.t, access_token) :: resp

Retrieves a list of granted permissions

Example

iex> Facebook.permissions("<Some Id>", "<Access Token>")
{:ok, %{"data" => [%{"permission" => "...", "status" => "..."}]}}

See: https://developers.facebook.com/docs/graph-api/reference/user/permissions

picture(user_id, type, access_token)

Specs

picture(user_id :: String.t, type :: String.t, access_token) :: resp

A Picture for a Facebook User

Example

iex> Facebook.picture("<Some Id>", "small", "<Access Token>")
{:ok, %{"data": "..."}}

See: https://developers.facebook.com/docs/graph-api/reference/user/picture/

publish(atom, feed_id, fields, access_token)

Specs

publish(:feed, feed_id :: String.t, fields, access_token) :: resp

Publish to a feed. Author (user or page) is determined from the supplied token.

The feed_id is the id for the user or page feed to publish to. Apps need both manage_pages and publish_pages to be able to publish as a Page. The publish_actions permission is required to publish as an individual.

See Facebook’s publishing documentation for more info:

Examples

iex> # publish a message
iex> Facebook.publish(:feed, "<Feed Id>", [message: "<Message Body"], "<Access Token>")
{:ok, %{"id" => "{page_id}_{post_id}"}}

iex> # publish a link and message
iex> Facebook.publish(:feed, "<Feed Id>", [message: "<Message Body", link: "www.example.com"], "<Access Token>")
{:ok, %{"id" => "{page_id}_{post_id}"}}
publish(atom, page_id, file_path, fields, access_token)

Specs

publish(:photo, page_id, file_path, fields, access_token) :: resp
publish(:video, page_id, file_path, fields, access_token) :: resp

Publish media to a feed. Author (user or page) is determined from the supplied token.

The feed_id is the id for the user or page feed to publish to. Same :feed publishing permissions apply.

Example

iex> Facebook.publish(:photo, "<Feed Id>", "<Image Path>", [], "<Access Token>")
{:ok, %{"id" => photo_id, "post_id" => "{page_id}_{post_id}"}

iex> Facebook.publish(:video, "<Feed Id>", "<Video Path>", [], "<Access Token>")
{:ok, %{"id" => video_id}

See: https://developers.facebook.com/docs/pages/publishing#fotos_videos

set_appsecret(appsecret)

If you want to use an appsecret proof, pass it into set_appsecret:

Example

iex> Facebook.set_appsecret("appsecret")

See: https://developers.facebook.com/docs/graph-api/securing-requests

start(type, args)

Start hook

start_link(_)

Supervisor start

test_users(app_id, access_token)

Specs

test_users(String.t, String.t) :: resp

Get all test users for an app.

The access token in this case needs to be an app access token. See:

Examples

iex> Facebook.test_users(“appId”, “appId|appSecret”) {:ok, %{“data” => [

%{
  "access_token" => "ACCESS_TOKEN",
  "id" => "USER_ID",
  "login_url" => "https://developers.facebook.com/checkpoint/test-user-login/USER_ID/"
}

]}