Matthew Berman
Matthew Berman

Reputation: 8631

How to subscribe to facebook realtime updates of a specific page's conversations

I'm trying to figure out how to subscribe to realtime updates to a page I have an access_token for (but not my app's page). I'm using the Koala gem and everything seems fine but I can't seem to figure out how to specify which page I want to subscribe to:

@updates = Koala::Facebook::RealtimeUpdates.new(:app_id => YOUR_APP_ID, :app_access_token => YOUR_ACCESS_TOKEN)
@updates.subscribe("page", "conversations", YOUR_CALLBACK_URL, YOUR_VERIFY_TOKEN)

the above is the code Koala says to implement but it doesn't say anywhere about how to choose which page we are subscribing to or where to insert the page_access_token.

Even when looking at the facebook example it doesn't have anywhere to enter the page access token.

Where do I specify which facebook page I want so subscribe to?

EDIT: When you subscribe to a "page" "conversations" which page are you subscribing to? All of them associated with a app_access_token? How do I know which pages are associated with the app_access_token?

Upvotes: 3

Views: 494

Answers (2)

Aswin Ramakrishnan
Aswin Ramakrishnan

Reputation: 3213

Here is how I have Koala implemented in my app and I've been getting a page's conversation (not through RealtimeUpdates) successfully. Here is how I did it -

I added the following to my Gemfile

gem 'omniauth-facebook'
gem 'koala'

I created a YAML file for facebook credentials -

development:
   app_id: <APP ID>
   secret: <APP Secret>

I added the following initializers under config/initializers

1.Facebook initializer as facebook.rb -

FACEBOOK_CONFIG = YAML.load_file("#{::Rails.root}/config/facebook.yml")[::Rails.env]

2.Omniauth initializer as omniauth.rb -

Rails.application.config.middleware.use OmniAuth::Builder do  
    provider :facebook, FACEBOOK_CONFIG['app_id'], FACEBOOK_CONFIG['secret'], {: scope => 'read_mailbox'}
end

The permission read_mailbox is key. If you're not sure if you have the read_mailbox permission, you might have to request it under Status and Review tab under your App's page (see screenshot below) -

enter image description here

Even though I'm not using RealTimeUpdates, I do something like the following to get the conversations -

def get_conversations(page_id)
   access_token ||= Koala::Facebook::OAuth.new(FACEBOOK_CONFIG['app_id'], FACEBOOK['secret']).get_app_access_token

   graph = Koala::Facebook::GraphAPI.new(access_token)
   @fb_conversations = graph.get_object(page_id + '/conversations')
end

Try hitting the Graph API explorer with {page_id}/conversations with your access token and see if you're getting an error.

Upvotes: 0

Tobi
Tobi

Reputation: 31479

In the example you linked, there IS some code to specify the Page Access Token:

Look at the bottom PHP script example:

$session = new FacebookSession('<PAGE_ACCESS_TOKEN>');

For setting Page Access Tokens, have a look at

Upvotes: 2

Related Questions