What is verify token in Facebook Realtime API

有些话、适合烂在心里 提交于 2019-12-02 02:19:42

Use POST rather than GET, with an empty body & object, fields, callback_url and verify_token passed as query parameters in the url.

See https://developers.facebook.com/docs/reference/api/realtime/.

Ankit Rastogi

I've figured this out... . . . . Make a POST request to url :

'https://graph.facebook.com/' + FB_CLIENT_ID + '/subscriptions?access_token=' + app_access_token + '&object=page&fields=name&callback_url=' + YOUR_CALLBACK_URL + '&verify_token=' + ANY_RANDOM_STRING + '&method=post'

Pass {} as post parameters..... Make sure that your_callback_url should be reachable. It will not work on localhost(I guess so... I was not able test it on localhost.)

So in Python the code should be :

url = 'https://graph.facebook.com/' + FB_CLIENT_ID + '/subscriptions?access_token=' + app_access_token + '&object=page&fields=name&callback_url=' + YOUR_CALLBACK_URL + '&verify_token=' + ANY_RANDOM_STRING + '&method=post'

url_params = {}

urlResponse = urllib2.urlopen(url, urllib.urlencode(url_params), timeout=socket.getdefaulttimeout()).read()

urlResponse should be null.

Function attached with callback_url should return:

def callback_function(request):
   if request.GET: #(Handle this properly!!!)
       return request.GET.get('hub.challenge') #hub_challenge for PHP Developers. :)

Please let me know in case of any doubts!!!

To know how to handle notifications from the FB: Kindly visit the following URL: Handling notifications request from Facebook after successful subscription

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!