2012-02-29 12 views
0

FacebookのリアルタイムAPIを実装しようとしています。 サブスクリプションを正常に追加しました。 (方法を見つけるためのURLをご覧ください... What is verify token in Facebook Realtime APIサブスクリプションに成功した後のFacebookからの通知の処理

しかし、私はFBから任意の通知が届きません。 ユーザーが何らかの変更を行うたびに、FBはcallback_url(私のサイトのアクセスログをチェックする)にPOSTコールを行います。しかし、データをファイルに書き込むことはできません。

私のコードは次のとおりです。

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ファイル:

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

これを行う方法を知ってはいけない....助けてください

答えて

1

Facebookのサブスクリプションのコールバックエントリをログに記録するようによるとステータス403 Forbiddenを取得し、これはコードが実行される前に発生します。

/fb_subscriptionsにアクセスしてコードが動作していることを確認してください。

ウェブサーバーのログレベルを上げて、リクエストがブロックされている理由を詳しく知ることができます。

+1

ありがとうございます!!! 私はそれが403(禁止されている)を投げていることに気付かなかった..... それはCSRFのためだ.... だから、このエラーを避けるためにはPythonで.... @csrf_exemptデコレータを使う。 –

関連する問題