[英]Facebook Graph API call without any gem
Is it possible to use just Rails (without any gem) to interact with Facebook's Graph API?是否可以仅使用 Rails(没有任何 gem)与 Facebook 的 Graph API 进行交互?
Can you provide an example on how to do that and get only the JSON respond back?你能提供一个例子来说明如何做到这一点并且只让 JSON 回复吗? (with or without access_token)
(有或没有 access_token)
I think I have to use Net::HTTP or something similar to curl in PHP?我想我必须在 PHP 中使用 Net::HTTP 或类似于 curl 的东西?
Thanks谢谢
Depends what you mean by 'interact with'.取决于您所说的“互动”是什么意思。 To simply retrieve a Facebook Graph URL, you can use:
要简单地检索 Facebook 图形 URL,您可以使用:
require 'open-uri'
file = open("https://graph.facebook.com/19292868552")
file.read
To parse the JSON,要解析 JSON,
require 'json'
JSON.parse()
There are a few different HTTP libraries though, and a few different JSON ones - so look around before settling on a solution.虽然有一些不同的 HTTP 库,还有一些不同的 JSON 库 - 所以在确定解决方案之前先看看周围。 Or use one of the gems that abstract away some of the Facebook Graph API calls.
或者使用抽象出一些 Facebook Graph API 调用的 gem 之一。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.