Facebook Realtime API 中的验证令牌是什么

发布于 2025-01-07 06:32:19 字数 785 浏览 2 评论 0原文

我正在尝试使用我的应用程序实现 Facebook Realtime api。我想从我的“Facebook 页面”中提取提要。 我已经获得了 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)

每次我使用 url 参数调用 url 时,都会收到错误:HTTP 错误 400: 错误请求 但是如果我调用没有 url 参数的 url,我会得到 {"data": []}

请注意,在 url 参数中,我使用 verify_token,一个随机字符串,而 callback_url 与facebook应用程序的redirect_url参数。(只是想知道是否有必要在这里输入相同的url?)

请告诉我我做错了什么? 我使用 python/django 来实现。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

小忆控 2025-01-14 06:32:19

使用 POST 而不是 GET,正文为空objectfieldscallback_urlverify_token 作为 url 中的查询参数传递。

请参阅https://developers.facebook.com/docs/reference/api/realtime/< /a>.

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

☆獨立☆ 2025-01-14 06:32:19

我已经弄清楚了这一点...




向 url 发出 POST 请求:

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

将 {} 作为 post 参数传递......
确保 your_callback_url 应可访问。它不会在本地主机上工作(我想是这样......我无法在本地主机上测试它。)

所以在Python中代码应该是:

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应该为null。

附有callback_url的函数应该返回:

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

如有任何疑问,请告诉我!

要了解如何处理来自 FB 的通知:
请访问以下网址:
成功订阅后处理来自 Facebook 的通知请求

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文