Giter Site home page Giter Site logo

mogli's Introduction

The first version of a Facebook Open Graph Library for Ruby. Require HTTParty to function.

For documentation on the Open Graph Library, see: http://developers.facebook.com/docs/api

======================================
Quick Start:
======================================

Add config.gem "mogli" to environment.rb

For Rails: create a controller like the following:

class OauthController < ApplicationController

  def new
    session[:at]=nil
    redirect_to authenticator.authorize_url(:scope => 'publish_stream', :display => 'page')
  end
  
  def create    
    mogli_client = Mogli::Client.create_from_code_and_authenticator(params[:code],authenticator)
    session[:at]=mogli_client.access_token
    redirect_to "/"
  end
  
  def index
    redirect_to new_oauth_path and return unless session[:at]
    user = Mogli::User.find("me",Mogli::Client.new(session[:at]))
    @user = user
    @posts = user.posts
  end
  
  def authenticator
    @authenticator ||= Mogli::Authenticator.new('client_id', 
                                         'secret', 
                                         oauth_callback_url)
  end
end


with routes:

map.resource :oauth, :controller=>"oauth"
map.root :controller=>"oauth"
map.oauth_callback "/oauth/create", :controller=>"oauth", :action=>"create"

Viewing / should redirect you to the login page, and then redirect back to your app to show your recent posts

From the console, you can create a client with the stored access token:


require "rubygems"
require "mogli"
client = Mogli::Client.new("your_access_token")

You can now fetch users with the client, for example:

myself  = Mogli::User.find("me",client)

or

mikemangino = Mogli::User.find(12451752,client)

When you fetch yourself, you can look at your posts and other information:

myself.posts


You can also fetch other objects by ID, for example:

album = Mogli::Album.find(99394368305)
album.photos

If the object requires a client, just pass one in:

album = Mogli::Album.find(99394368305,client)
album.photos

You can also upload photos using httmultiparty:
facebook_access_token = "..."
client = Mogli::Client.new(facebook_access_token)
client.post("me/photos", nil, {:source => File.open("myphoto.jpg")})

========================================
Contributing
========================================

1) fork the repo
2) Add tests for a missing method, such as client.post(post_id)
3) implement missing method
4) send me a pull request.

Feel free to add missing associations if you see them as well. My goal is to get a readonly API in place first, and then move on to the read/write API

Mike

mogli's People

Contributors

mmangino avatar sferik avatar dnurzynski avatar pomartel avatar braindeaf avatar anthonymorrisjohnson avatar jackca avatar simianarmy avatar srushti avatar meuble avatar treybean avatar bcm avatar herval avatar byroot avatar ncavig avatar adahmash avatar taweili avatar jkassemi avatar jaredonline avatar jeffdeville avatar jonasfa avatar jpr5 avatar kdmny avatar kbighorse avatar leckylao avatar stupied4ever avatar raghums avatar r38y avatar reidab avatar pragmaticsc avatar

Stargazers

 avatar

Watchers

 avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.