Class: Fobos::GraphAPI::Pages
- Inherits:
-
Object
- Object
- Fobos::GraphAPI::Pages
- Includes:
- HTTParty
- Defined in:
- lib/fobos/graph_api/pages.rb
Constant Summary collapse
- FB_URI =
Store Facebook default URL
'https://www.facebook.com'- GRAPH_URI =
Store Facebook Graph API URL
'https://graph.facebook.com'
Instance Attribute Summary collapse
-
#access_token ⇒ Object
You can get access token with Fobos::GraphAPI::Oauth.
Instance Method Summary collapse
-
#get_accounts ⇒ Object
Return list of user’s accounts.
-
#get_feed(page_id, options = {}) ⇒ Object
Return feed list of page.
-
#initialize(access_token) ⇒ Pages
constructor
Need access token for making calls.
-
#post_to_page(page_id, page_access_token, options = {}) ⇒ Object
Publishing post to the page wall.
Constructor Details
#initialize(access_token) ⇒ Pages
Need access token for making calls.
18 19 20 |
# File 'lib/fobos/graph_api/pages.rb', line 18 def initialize(access_token) @access_token = access_token end |
Instance Attribute Details
#access_token ⇒ Object
You can get access token with Fobos::GraphAPI::Oauth.
10 11 12 |
# File 'lib/fobos/graph_api/pages.rb', line 10 def access_token @access_token end |
Instance Method Details
#get_accounts ⇒ Object
Return list of user’s accounts.
Use access_token from Fobos::GraphAPI::Pages.new
25 26 27 28 |
# File 'lib/fobos/graph_api/pages.rb', line 25 def get_accounts user = Fobos::GraphAPI::Users.new(@access_token) user.get_request(fields: 'accounts') end |
#get_feed(page_id, options = {}) ⇒ Object
Return feed list of page.
Use access_token from Fobos::GraphAPI::Pages.new
51 52 53 54 55 56 57 58 |
# File 'lib/fobos/graph_api/pages.rb', line 51 def get_feed(page_id, = {}) = '' = .map {|k,v| "#{k}=#{v.kind_of?(Array) ? v.join(',') : v}" }.join('&') unless .empty? query = GRAPH_URI.to_s + "/#{page_id}" + "/feed?#{options_part}&access_token=#{@access_token}" self.class.get(query) end |
#post_to_page(page_id, page_access_token, options = {}) ⇒ Object
Publishing post to the page wall.
If you call it with USER_ACCESS_TOKEN it will publish post from user!
If you want publish something from Page you need call it with PAGE_ACCESS_TOKEN. You can get it from list of user’s account returned by Fobos::GraphAPI::Pages.get_accounts.
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/fobos/graph_api/pages.rb', line 35 def post_to_page(page_id, page_access_token, = {}) = '' = .map {|k,v| "#{k}=#{v.kind_of?(Array) ? v.join(',') : v}" }.join('&') unless .empty? query = GRAPH_URI.to_s + "/#{page_id}" + "/feed?#{options_part}&access_token=#{page_access_token}" encoded_url = URI.encode(query) puts encoded_url self.class.post(URI.parse(encoded_url)) end |