jgorset / facebook-messenger

Definitely the best way to make Bots on Facebook Messenger with Ruby
MIT License
962 stars 211 forks source link

The parameter subscribed_fields is required #231

Closed rafayet-monon closed 5 years ago

rafayet-monon commented 6 years ago

I am facing this error with facebook-messenger-0.11.1.

`raise_errors': (#100) The parameter subscribed_fields is required (Facebook::Messenger::Subscriptions::Error)

from /home/user/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/facebook-messenger-0.11.1/lib/facebook/messenger/subscriptions.rb:20:in `subscribe'

How can I fix this error?

amrutjadhav commented 6 years ago

@rafayet-monon facebook-messenger-0.11.1 gem works on graph API v2.6 and as of July 13, 2018, this API is unavailable. So I would suggest you, use facebook-messenger-1.1.1 which works on graph API v2.9. And graph API v2.9 don't need subscribed_fields parameter while subscription.

Salimchorfi commented 6 years ago

@amrutjadhav i got the same issue and switch to facebook-messanger-1.1.1, but i'm still getting the same error:

.rvm/gems/ruby-2.4.2/gems/facebook-messenger-1.1.1/lib/facebook/messenger/subscriptions.rb:73:in raise_errors': (#100) The parameter subscribed_fields is required. (Facebook::Messenger::Subscriptions::Error)

rafayet-monon commented 6 years ago

Same here, also got the problem after switching to 1.1.1. @amrutjadhav . Are we missing anything. It would be a big help if you pointed out.

amrutjadhav commented 6 years ago

@rafayet-monon It's very strange. Because currently I am using facebook-messenger-v1.1.1 and everything is working fine for me. If you share your code/sample, I could check it out.

rafayet-monon commented 6 years ago

@amrutjadhav Actually I am trying to run this project with api-ai. here is the gist that contains connection to subscription.

amrutjadhav commented 6 years ago

@rafayet-monon Sorry, but I couldn't understand the reason behind your error as the shared code looks correct. And documentation of subscription on Graph API v2.9 also don't require subscribed_fields. I would suggest you to check FB developer panel and check whether everything is OK. You could also try by creating a new app and check if the error still exists.

artyomlagun commented 6 years ago

hello guys! I faced with a similar problem. my FB application created with API v3.2 and I assume this problem happened, because of FB API v3.1+ require subscription_fields (https://developers.facebook.com/docs/graph-api/reference/page/subscribed_apps#Creating).

I think if add the second defined parameter to subscribe method, like

def subscribe(access_token:, subscription_fields: [])

it will fix the problem

artyomlagun commented 6 years ago

but I could be wrong

artyomlagun commented 6 years ago

@jgorset I think, it will be helpful https://github.com/jgorset/facebook-messenger/pull/232

amrutjadhav commented 6 years ago

@artyomlagun https://github.com/jgorset/facebook-messenger/pull/232#issuecomment-438509249

Ericfreespirit commented 5 years ago

Same problem guys :(

Snakultime commented 5 years ago

Same problem too ^^' Facebook has change API 2.9 to 3.2. Maybe it's that.

Fredis commented 5 years ago

Guys,

Does anyone found a solution? I got the same error on Heroku: "(#100) The parameter subscribed_fields is required. (Facebook::Messenger::Subscriptions::Error)" ?

Best regards, Fred.

Snakultime commented 5 years ago

OK!; Just remove 'Facebook::Messenger::Subscriptions.subscribe(access_token: access_token)' And working good.

jgorset commented 5 years ago

This is happening because this endpoint targets Graph API 2.9, but new apps no longer support targeting that. We'll need to upgrade the endpoint to using Graph API 3.2, and implement support for subscription_fields to the subscribe method.

You were onto something, then, @artyomlagun! In fact the only thing you didn't do was to upgrade the version in the endpoint! If you revise your pull request, I'll be happy to merge it.

Here are the options for an app created a long time ago

screen shot 2018-12-05 at 11 11 23

Here are the options for an app created today

screen shot 2018-12-05 at 11 12 51
joaotorres commented 5 years ago

Any updates on this? Did anyone manage to make this work? We're getting the same subscribed_fields is required error :(

joaotorres commented 5 years ago

@artyomlagun #232 (comment)

I used your gem, but seems you misnamed the parameter, or I don't know if it had another name on the previous version. I cloned it and changed the name (from subscription_fields to subscribed_fields), but then it still complains if the field is empty, though with another error:

Unable to load application: Facebook::Messenger::Subscriptions::Error: An unknown error has occurred.

But then if you specify one of the fields, it complains about permissions:

Unable to load application: Facebook::Messenger::Subscriptions::Error: (#200) To subscribe to the messages field, one of these permissions is needed: manage_pages

Any ideas?

jgorset commented 5 years ago

I took @artyomlagun's pull request the rest of the way and released a new version 1.1.2 that should fix this issue.

habipyesilyurt17 commented 5 years ago

If you are using Graph API v3.2 or upper version, please add one additional parameter in the POST request ,

subscribed_fields=leadgen

stabgan commented 5 years ago

what's leadgen ?

artyomlagun commented 5 years ago

@habipyesilyurt17 @stabgan

which params subscribed_apps use https://developers.facebook.com/docs/graph-api/reference/page/subscribed_apps#Creating - you able to see in the Parameters section (the leadgen on the 9th line from the bottom).

and you should call subscribe method like:

Facebook::Messenger::Subscriptions.subscribe(access_token: @page_token, subscribed_fields: SUBSCRIBED_PARAMS, page_id: @page_id)

your SUBSCRIBED_PARAMS should be: SUBSCRIBED_PARAMS = [ 'messages', 'message_echoes', 'message_deliveries', 'messaging_optins', 'leadgen' ]

artyomlagun commented 5 years ago

I took @artyomlagun's pull request the rest of the way and released a new version 1.1.2 that should fix this issue.

sorry, I've not seen your comment :) but I'm glad that my PR was helpful