Handling notifications request from Facebook after successful subscription

匆匆过客 提交于 2019-12-23 04:24:39

问题


I'm trying to implement Facebook realtime API. I've added a subscription successfully. (PLease visit url to find out how... What is verify token in Facebook Realtime API )

But I'm not getting any notifications from FB. Whenever a user makes any changes, FB makes a POST call to my callback_url(I checkecd the access logs of my site). But I'm not able to write the data to a file.

My CODE IS:

from datetime import datetime
def fb_notifications(request):
    handle1=open('/path_to_log_file/smt_logs.log','a+')
    handle1.write('\n<<<<<Log accessed at ' + str(datetime.now()) + '>>>>>>')
    handle1.close();
    if request.GET: (#This is working properly.....)
        handle1=open('/var/smt_logs/smt_logs.txt','a+')
        handle1.write('\n---------------Subscription STARTS at ' + str(datetime.now()) + ' ----------------------------' + '\n')
        handle1.write(str(request))
        handle1.write('\n-----------------END--------------------------' + '\n\n')
        handle1.close();
        code = request.GET.get('hub.challenge')     
        return HttpResponse(code)
    elif request.POST:(#This is not working... Trying to write data to a File....)
        handle1=open('/path_to_log_file/smt_logs.log','a+')
        handle1.write('\n---Notification STARTS at ' + str(datetime.now()) + ' ---' + '\n')
        handle1.write(str(request))
        handle1.write('\n---END---' + '\n\n')
        handle1.close();
    else:
        handle1=open('/path_to_log_file/smt_logs.log','a+')
        handle1.write('\n---Error at ' + str(datetime.now()) + ' ---' + '\n')
        handle1.write('\n---END---' + '\n\n')
        handle1.close();
        return HttpResponse('Error! Please try again.')

LOG FILE :

66.220.145.247 - - [29/Feb/2012:13:05:03 +0530] "POST /fb_notifications/ HTTP/1.1" 403 2528 "-" "-"
66.220.155.117 - - [29/Feb/2012:13:05:47 +0530] "POST /fb_notifications/ HTTP/1.1" 403 2509 "-" "-"
66.220.145.247 - - [29/Feb/2012:13:06:38 +0530] "POST /fb_notifications/ HTTP/1.1" 403 2528 "-" "-"
66.220.145.250 - - [29/Feb/2012:13:08:42 +0530] "POST /fb_notifications/ HTTP/1.1" 403 2528 "-" "-"
66.220.151.123 - - [29/Feb/2012:13:08:45 +0530] "POST /fb_notifications/ HTTP/1.1" 403 2528 "-" "-"
66.220.151.121 - - [29/Feb/2012:13:09:14 +0530] "POST /fb_notifications/ HTTP/1.1" 403 2528 "-" "-"
66.220.145.245 - - [29/Feb/2012:13:10:04 +0530] "POST /fb_notifications/ HTTP/1.1" 403 2528 "-" "-"
66.220.145.248 - - [29/Feb/2012:13:10:05 +0530] "POST /fb_notifications/ HTTP/1.1" 403 2528 "-" "-"
66.220.145.246 - - [29/Feb/2012:13:11:14 +0530] "POST /fb_notifications/ HTTP/1.1" 403 2528 "-" "-"
66.220.145.248 - - [29/Feb/2012:13:12:25 +0530] "POST /fb_notifications/ HTTP/1.1" 403 2528 "-" "-"
66.220.151.120 - - [29/Feb/2012:13:14:11 +0530] "POST /fb_notifications/ HTTP/1.1" 403 2528 "-" "-"
66.220.155.118 - - [29/Feb/2012:13:15:12 +0530] "POST /fb_notifications/ HTTP/1.1" 403 2509 "-" "-"
66.220.151.120 - - [29/Feb/2012:13:15:59 +0530] "POST /fb_notifications/ HTTP/1.1" 403 2528 "-" "-"
66.220.151.123 - - [29/Feb/2012:13:16:01 +0530] "POST /fb_notifications/ HTTP/1.1" 403 2528 "-" "-"
66.220.151.121 - - [29/Feb/2012:13:24:43 +0530] "POST /fb_notifications/ HTTP/1.1" 403 2528 "-" "-"
66.220.151.120 - - [29/Feb/2012:13:25:22 +0530] "POST /fb_notifications/ HTTP/1.1" 403 2528 "-" "-"
66.220.145.248 - - [29/Feb/2012:13:25:51 +0530] "POST /fb_notifications/ HTTP/1.1" 403 2528 "-" "-"
66.220.151.121 - - [29/Feb/2012:13:26:14 +0530] "POST /fb_notifications/ HTTP/1.1" 403 2528 "-" "-"
66.220.145.246 - - [29/Feb/2012:13:26:27 +0530] "POST /fb_notifications/ HTTP/1.1" 403 2528 "-" "-"

Don't know how to do this.... Please help


回答1:


According to log entries Facebook subscription callback get status 403 Forbidden and this happens before your code run.

Ensure you're able to reach /fb_subscriptions for your application and code is running.

You may want to use increase log level of your web-server to get more detailed information why request is blocked...



来源:https://stackoverflow.com/questions/9495461/handling-notifications-request-from-facebook-after-successful-subscription

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