What is verify token in Facebook Realtime API

岁酱吖の 提交于 2019-12-02 03:49:30

问题


I'm trying to implement Facebook Realtime api with my application. I want to pull the feeds from my 'facebook PAGE'. I've obtained app_access_token...

app_access_token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxx'       

url = 'https://graph.facebook.com/' + FB_CLIENT_ID + '/subscriptions?access_token=' + app_access_token

url_params = {'access_token':app_access_token,'object':'page', 'fields':'feed', 'callback_url':'http://127.0.0.1:8000/fb_notifications/', 'verify_token' : 'I am taking a random string here...'}

urlResponse = call_url(url, url_params)

Everytime I call the url with url parameters, I get error : HTTP Error 400: Bad Request But If I call the url without url parameters, I get {"data": []}

Please note that in url parameters, I'm taking verify_token, a random string and callback_url is not same as the redirect_url parameter for the facebook application.(just wanna know is it necessary to put the same url here?)

Please tell me what I'm doing wrong? I'm using python/django to implement.


回答1:


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/.




回答2:


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



来源:https://stackoverflow.com/questions/9360774/what-is-verify-token-in-facebook-realtime-api

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