3

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?

Matthew Berman
  • 8,481
  • 10
  • 49
  • 98

2 Answers2

2

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

Tobi
  • 31,405
  • 8
  • 58
  • 90
  • yea but how do I pass the page access token to the @updates.subscribe (as shown in the koala gem) like so: @updates.subscribe("user", "first_name, last_name", YOUR_CALLBACK_URL, YOUR_VERIFY_TOKEN) – Matthew Berman Mar 03 '15 at 18:01
  • nothing in koala realtime updates asks for a token...i'm so confused – Matthew Berman Mar 03 '15 at 18:07
  • what I'm trying to do is subscribe to another page's conversations (not my own app's page) and I do have that page's access token – Matthew Berman Mar 03 '15 at 18:15
  • Do you know if you have `read_page_mailboxes` permissions for that page? – Aswin Ramakrishnan Mar 10 '15 at 19:40
  • 1
    You can only subscribe to a Page's conversations if the Page (respectively it's owner) added your app via `/{page-id}/subscribed_apps` (https://developers.facebook.com/docs/graph-api/reference/v2.2/page/subscribed_apps#publish). Concerning permissions, yes, you have to have `read_page_mailboxes` if you want to access the conversations (https://developers.facebook.com/docs/graph-api/reference/v2.2/page/conversations) – Tobi Mar 12 '15 at 08:58
0

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.

Aswin Ramakrishnan
  • 3,195
  • 2
  • 41
  • 65