facebook v0.14.0 Facebook
Provides API wrappers for the Facebook 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
Deprecated: Please use fanCount instead
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
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
reaction :: :reaction
response :: {:json, HashDict.t} | {:body, String.t}
using_appsecret :: boolean
Functions
Exchange an authorization code for an access token
Examples
iex> Facebook.accessToken("client_id", "client_secret", "redirect_uri", "code")
%{
"access_token" => "ACCESS_TOKEN",
"expires_in" => 5183976,
"token_type" => "bearer"
}
See: https://developers.facebook.com/docs/facebook-login/manually-build-a-login-flow#confirm
Specs
fanCount(page_id :: integer | String.t, access_token) :: integer
Get the count of fans for the provided page_id
Example
iex> Facebook.fanCount("CocaColaMx", "<Your Token>")
See: https://developers.facebook.com/docs/graph-api/reference/page/
Exchange a short lived access token for a long lived one
Examples
iex> Facebook.longLivedAccessToken("client_id", "client_secret", "access_token")
%{
"access_token" => "ACCESS_TOKEN",
"expires_in" => 5183976,
"token_type" => "bearer"
}
See: https://developers.facebook.com/docs/facebook-login/access-tokens/expiration-and-extension
Specs
me(fields :: String.t, access_token) :: response
me(fields, access_token) :: response
Basic user infos of the logged in user (specified by the access_token).
Example
iex> Facebook.me([fields: "id,first_name"], "<Your Token>")
See: https://developers.facebook.com/docs/graph-api/reference/user/
Specs
myLikes(access_token) :: response
Likes of the currently logged in user (specified by the access_token)
Example
iex> Facebook.myLikes("<Your Token>")
See: https://developers.facebook.com/docs/graph-api/reference/user/likes
Specs
objectCount(scope :: atom, object_id :: String.t, access_token) :: number
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 fanCount.
Expected scopes:
- :likes
- :comments
Example
iex> Facebook.objectCount(:likes, "1326382730725053_1326476257382367", "<Token>")
2
iex> Facebook.objectCount(:comments, "1326382730725053_1326476257382367", "<Token>")
2
See: https://developers.facebook.com/docs/graph-api/reference/object/likes See: https://developers.facebook.com/docs/graph-api/reference/object/comments
Specs
objectCount(reaction, react_type :: atom, object_id :: String.t, access_token) :: number
Gets the number of reactions that an object has.
Expected type of reactions:
- :haha
- :wow
- :thankful
- :sad
- :angry
- :love
- :none
Examples
iex> Facebook.objectCount(:reaction, :wow, "769860109692136_1173416799336463", "<Token>")
2
iex> Facebook.objectCount(:reaction, :haha, "769860109692136_1173416799336463", "<Token>")
12
iex> Facebook.objectCount(:reaction, :thankful, "769860109692136_1173416799336463", "<Token>")
33
Specs
objectCountAll(object_id :: String.t, access_token) :: map
Get all the object reactions with single request.
Examples
iex> Facebook.objectCountAll("769860109692136_1173416799336463", "<Token>")
%{"angry" => 0, "haha" => 1, "like" => 0, "love" => 0, "sad" => 0, "wow" => 0}
Specs
page(page_id :: integer | String.t, access_token) :: response
Basic page information for the provided page_id
Example
iex> Facebook.page("CocaColaMx", "<Your Token>")
See: https://developers.facebook.com/docs/graph-api/reference/page
Specs
page(page_id :: integer | String.t, access_token, fields) :: response
Get page information for the specified fields for the provided page_id
Example
iex> Facebook.page("CocaColaMx", "<Your Token>", "id")
See: https://developers.facebook.com/docs/graph-api/reference/page
Specs
pageFeed(scope :: atom | String.t, page_id :: String.t, access_token, limit :: number, fields :: String.t) :: Map.t
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.pageFeed(:posts, "CocaColaMx", "<Your Token>")
iex> Facebook.pageFeed(:tagged, "CocaColaMx", "<Your Token>", 55)
iex> Facebook.pageFeed(:promotable_posts, "CocaColaMx", "<Your Token>")
iex> Facebook.pageFeed(:feed, "CocaColaMx", "<Your Token>", 55, "id,name")
See: https://developers.facebook.com/docs/graph-api/reference/page/feed
Specs
pageLikes(page_id :: integer | String.t, access_token) :: integer
Deprecated: Please use fanCount instead.
Get the count of fans for the provided page_id
Example
iex> Facebook.pageLikes("CocaColaMx", "<Your Token>")
See: https://developers.facebook.com/docs/graph-api/reference/page/
Specs
permissions(user_id :: integer | String.t, access_token) :: response
Retrieves a list of granted permissions
Example
iex> Facebook.permissions("<Some Id>", "<Your Token>")
See: https://developers.facebook.com/docs/graph-api/reference/user/permissions
Specs
picture(user_id :: String.t, type :: String.t, access_token) :: response
A Picture for a Facebook User
Example
iex> Facebook.picture("<Some Id>", "small", "<Your Token>")
See: https://developers.facebook.com/docs/graph-api/reference/user/picture/
Specs
publish(:feed, feed_id :: String.t, fields, access_token) :: response
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:
- https://developers.facebook.com/docs/pages/publishing
- https://developers.facebook.com/docs/pages/publishing#personal_post
- https://developers.facebook.com/docs/facebook-login/permissions#reference-publish_pages
Examples
iex> # publish a message
iex> Facebook.publish(:feed, "<Feed Id>", [message: "<Message Body"], "<Acess Token>")
iex> # publish a link and message
iex> Facebook.publish(:feed, "<Feed Id>", [message: "<Message Body", link: "www.example.com"], "<Access Token>")
If you want to use an appsecret proof, pass it into set_appsecret:
Example
iex> Facebook.setAppsecret("appsecret")
See: https://developers.facebook.com/docs/graph-api/securing-requests
Get all test users for an app.
The access token in this case needs to be an app access token. See:
- https://developers.facebook.com/docs/facebook-login/access-tokens#apptokens
- https://developers.facebook.com/docs/graph-api/reference/v2.8/app/accounts/test-users
Examples
iex> Facebook.testUsers(“appId”, “appId|appSecret”) [
%{
"access_token" => "ACCESS_TOKEN",
"id" => "USER_ID",
"login_url" => "https://developers.facebook.com/checkpoint/test-user-login/USER_ID/"
}
]