成功订阅后处理来自Facebook的通知请求 [英] Handling notifications request from Facebook after successful subscription

查看:113
本文介绍了成功订阅后处理来自Facebook的通知请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试实现Facebook实时API。
我已经成功添加了一个订阅。
(PLease visit url to find out how ...
什么是Facebook中的验证令牌实时API



但是我没有收到FB的任何通知。
每当用户进行任何更改时,FB会对我的callback_url进行POST调用(我检查我的站点的访问日志)。但是我无法将数据写入文件。



我的代码是:

 def fb_notifications(request):
handle1 = open('/ path_to_log_file / smt_logs.log','a +')
handle1.write '\\\
<<<<<日志访问'+ str(datetime.now())+'>>>>>>')
handle1.close );
如果request.GET:(#This正常工作.....)
handle1 = open('/ var / smt_logs / smt_logs.txt','a +')
handle1。写('\\\
---------------订阅STARTS at'+ str(datetime.now())+'-------------- --------------'+'\\\
')
handle1.write(str(request))
handle1.write('\\\
--- -------------- END --------------------------'+'\\\
\\\
')
handle1.close();
code = request.GET.get('hub.challenge')
返回HttpResponse(代码)
elif request.POST:(#This不工作...试图将数据写入一个文件....)
handle1 = open('/ path_to_log_file / smt_logs.log','a +')
handle1.write('\\\
---通知STARTS at'+ str datetime.now())+'---'+'\\\
')
handle1.write(str(request))
handle1.write('\\\
--- END- - '+'\\\
\\\
')
handle1.close();
else:
handle1 = open('/ path_to_log_file / smt_logs.log','a +')
handle1.write('\\\
---'at'+ str(datetime) now())+'---'+'\\\
')
handle1.write('\\\
--- END ---'+'\\\
\\\
')
handle1.close();
return HttpResponse('Error!Please try again。')

LOG FILE: p>

  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.1403 2509 - -
66.220.145.247 - - [29 / Feb / 2012:13:06:38 +0530]POST / fb_notifications / HTTP / 1.1403 2528 - -
66.220.145.250 - [29 / Feb / 2012:13:08:42 +0530]POST / fb_notifications / HTTP / 1.1403 2528 - -
66.220.151.123 - - [29 / Feb / 2012:13: 08:45 +0530]POST / fb_notifications / HTTP / 1.1403 2528 - -
66.220.151.121 - - [29 / Feb / 2012:13:09:14 +0530] fb_notifications / HTTP / 1.1403 2528 - -
66.220.145.245 - - [29 / Feb / 2012:13:10:04 +0530]POST / fb_notifications / HTTP / 1.1403 2528 - -
66.220.145.248 - - [29 / Feb / 2012:13:10:05 +0530]POST / fb_notifications / HTTP / 1.1403 2528 - -
66.220.145.246 - - [29 / Feb / 2012:13:11:14 +0530]POST / fb_notifications / HTTP / 1.1403 2528 - -
66.220.145.248 - - [29 / Feb / 2012:13: 25 +0530]POST / fb_notifications / HTTP / 1.1403 2528 - -
66.220.151.120 - - [29 / Feb / 2012:13:14:11 +0530]POST / fb_notifications / HTTP / 1.1403 2528 - -
66.220.155.118 - - [29 / Feb / 2012:13:15:12 +0530]POST / fb_notifications / HTTP / 1.1403 2509 -
66.220.151.120 - - [29 / Feb / 2012:13:15:59 +0530]POST / fb_notifications / HTTP / 1.1403 2528 - -
66.220。 151.123 - - [29 / Feb / 2012:13:16:01 +0530]POST / fb_notifications / HTTP / 1.1403 2528 - -
66.220.151.121 - - [2012年2月29日:13:24:43 +0530]POST / fb_notifications / HTTP / 1.1403 2528 - -
66.220.151.120 - - [29 / Feb / 2012:13:25:22 +0530] POST / fb_notifications / HTTP / 1.1403 2528 - -
66.220.145.248 - - [29 / Feb / 2012:13:25:51 +0530]POST / fb_notifications / HTTP / 403 2528 - -
66.220.151.121 - - [29 / Feb / 2012:13:26:14 +0530]POST / fb_notifications / HTTP /1.1403 2528 - -
66.220.145.246 - - [29 / Feb / 2012:13:26:27 +0530]POST / fb_notifications / HTTP / 1.1403 2528 - -

不知道该怎么做....请帮助

解决方案

根据日志条目,Facebook订阅回调获取状态 403 Forbidden



确保您能够达到 / fb_subscriptions ,以便您的应用程序和代码正在运行。 >

您可能希望使用Web服务器的增加日志级别获取更多详细信息,以阻止请求被阻止...


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

解决方案

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

这篇关于成功订阅后处理来自Facebook的通知请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆