You could use Koala:
Koala is a Facebook library for Ruby, supporting the Graph API (including the batch requests and photo uploads), the REST API, realtime updates, test users, and OAuth validation
题
i have a ruby on rails 3.2.13 app, and i want to fetch data from my facebook page and show it one of my views...
What steps should i follow to do this?
What has to go in my controller and model and also in my view?
Please Help! ive been investigating on how to do this for like a week now, and i cannot find a good tutorial on how to get this done.
I have made a Data scaffold with the stuff i want to read from facebook.
This is my controller
class DatosController < ApplicationController
# GET /datos
# GET /datos.json
def index
@datos = JSON.parse("http://graph.facebook.com/iscopeapp")
respond_to do |format|
format.html # index.html.erb
format.json { render json: @datos }
end
end
# GET /datos/1
# GET /datos/1.json
def show
@dato = Dato.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.json { render json: @dato }
end
end
# GET /datos/new
# GET /datos/new.json
def new
@dato = Dato.new
respond_to do |format|
format.html # new.html.erb
format.json { render json: @dato }
end
end
# GET /datos/1/edit
def edit
@dato = Dato.find(params[:id])
end
# POST /datos
# POST /datos.json
def create
@dato = Dato.new(params[:dato])
respond_to do |format|
if @dato.save
format.html { redirect_to @dato, notice: 'Dato was successfully created.' }
format.json { render json: @dato, status: :created, location: @dato }
else
format.html { render action: "new" }
format.json { render json: @dato.errors, status: :unprocessable_entity }
end
end
end
# PUT /datos/1
# PUT /datos/1.json
def update
@dato = Dato.find(params[:id])
respond_to do |format|
if @dato.update_attributes(params[:dato])
format.html { redirect_to @dato, notice: 'Dato was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: @dato.errors, status: :unprocessable_entity }
end
end
end
# DELETE /datos/1
# DELETE /datos/1.json
def destroy
@dato = Dato.find(params[:id])
@dato.destroy
respond_to do |format|
format.html { redirect_to datos_url }
format.json { head :no_content }
end
end
end
This is my Model
class Dato < ActiveRecord::Base
attr_accessible :likes, :name, :talking_about_count
end
this is the facebook json link i want to parse and show some fields of it in my view.
When i access the index of this controller im getting an error : "Unexpected Token at:http://graph.facebook.com/iscopeapp" http://graph.facebook.com/iscopeapp
Please help!
Thank you in advance!
解决方案
You could use Koala:
Koala is a Facebook library for Ruby, supporting the Graph API (including the batch requests and photo uploads), the REST API, realtime updates, test users, and OAuth validation