使用 Ruby/Sinatra 和 Rest-Graph gem 在 Facebook 应用程序中获取signed_request
我使用 Sinatra 和 Rest-Graph gem 构建了一个 Facebook 应用程序。现在我想将应用程序作为 iframe 选项卡嵌入 Facebook 页面。
为此,我需要从 Facebook 发送到我的应用程序的 signed_request
中获取数据。
Rest-Graph gem 在其 Github 页面上声明了以下功能:
提取access_token和的实用程序 检查 cookies/signed_request 中的签名
我找不到任何有关如何使用此“实用程序”的文档。你能给我指点一些文档吗?或者更好的是,给我一个关于如何在 Ruby/Sinatra 中使用它的示例?
I've built a Facebook app using Sinatra and the Rest-Graph gem. Now I would like to embed the app as an iframe tab in a Facebook Page.
To do that, I need to fetch data from the signed_request
sent to my app by Facebook.
The Rest-Graph gem states the following feature on its Github page:
Utility to extract access_token and
check sig in cookies/signed_request
I couldn't find any documentation on how to use this "utility". Can you point me to some documentation or even better, give me an example on how this is used with Ruby/Sinatra?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
几乎所有可用的 Graph API 库都以类似的方式处理signed_request。 Rest-Graph 有一个 parse_signed_request 方法(Rest -Graph/lib/core.rb),您可以在 Sinatra 中调用它。
我使用 Koala 和 Sinatra 来完成此操作,它的工作原理与广告中所宣传的一样:
您可以返回 Facebook 发布的 JSON 对象的哈希值:
rest-graph 也使其变得非常简单。刚刚在 Sinatra 应用程序中对此进行了测试。完美运作:
让我知道这是否不适合您。
Nearly all of the Graph API libraries that are available deal with signed_request in a similar way. Rest-Graph has a parse_signed_request method (Rest-Graph/lib/core.rb) that you can call in Sinatra.
I'm using Koala for this with Sinatra, and it works as advertised:
You get back a hash of the JSON object that Facebook posts:
rest-graph makes it pretty easy, too. Just tested this in a Sinatra app. Works perfectly:
Lemme know if that doesn't work for you.
我刚刚收到来自“cardinalblue”的对该问题的回复< /a>,Rest-Graph gem 的开发者。这个小例子正是我正在寻找的:
旁注:如果您正在构建类似的东西,请注意
post '/' do
。 Facebook 页面使用 POST 请求而不是 GET 来获取您的页面。I just got a response to this question from "cardinalblue", the developer of the Rest-Graph gem. This little example was exactly what I was looking for:
Sidenote: In case you're building something similar, please note the
post '/' do
. Facebook Pages fetch your page using a POST request instead of a GET.