Class: Broadcast::Medium::Facebook
- Inherits:
-
Broadcast::Medium
- Object
- Broadcast::Medium
- Broadcast::Medium::Facebook
- Defined in:
- lib/broadcast/media/facebook.rb
Instance Method Summary collapse
Methods inherited from Broadcast::Medium
#initialize, #namespace, #options
Constructor Details
This class inherits a constructor from Broadcast::Medium
Instance Method Details
#publish(message) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/broadcast/media/facebook.rb', line 5 def publish() # We do not rescue any Koala exceptions to make them crash the sendout # This should make debugging easier i.e. when fb has privilege issues # Connect to facebook and get info about current user graph = Koala::Facebook::GraphAPI.new(.token) me = graph.get_object('me') # Get the connections to retrieve the appropriate page connections = graph.get_connections(me['id'], 'accounts') raise "No pages available" if connections.size == 0 # Find the page to post to page = connections.find { |connection| connection['name'] == .page } raise 'Page not found' if !page # Create a new graph so that the page posts to itself page_graph = Koala::Facebook::GraphAPI.new(page['access_token']) page_graph.put_wall_post(.body) end |