简体   繁体   English

从url中获取json对象,同时在rails上的ruby中使用facebook graph api

[英]Get a json object from the url while using facebook graph api in ruby on rails

how to get the JSON object through URL in my ruby on rails code: 如何通过我的ruby on rails代码中的URL获取JSON对象:

url = "https://graph.facebook.com/me/friends?access_token=XXX"

I am not able to get good tutorial for JSON + Ruby on rails. 我无法在rails上获得JSON + Ruby的优秀教程。 Can someone help me out thanks. 有人可以帮我谢谢。

require 'open-uri'
require 'json'

json_object = JSON.parse(open("https://graph.facebook.com/me/friends?access_token=XXX").read)

This is the simplest way, though it may not be the fastest. 这是最简单的方法,虽然它可能不是最快的。

Edit: If the URI contains special characters in its parameter string, it has to be escaped/encoded with URI.escape first. 编辑:如果URI的参数字符串中包含特殊字符,则必须首先使用URI.escape对其进行转义/编码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM