├── LICENSE ├── README.textile ├── facebook_oauth.gemspec └── lib ├── facebook_oauth.rb └── facebook_oauth ├── client.rb └── objects.rb /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) Richard Taylor 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.textile: -------------------------------------------------------------------------------- 1 | h1. Facebook OAuth Graph API client library for Ruby 2 | 3 | h2. Install the gem 4 | 5 | sudo gem install facebook_oauth 6 | 7 | h2. Using the gem 8 | 9 | To make authorized requests with the client library you'll need to "create a Facebook Application":http://www.facebook.com/developers/createapp.php. 10 | 11 | See "http://facebook-oauth.heroku.com/":http://facebook-oauth.heroku.com/ for a full integration example. 12 | 13 | h2. Authorized request example 14 | 15 | To use the full power of the Facebook API you need to authorize your application and a valid Facebook user via OAuth. 16 | An example showing how to update the status of an authorized user is below. 17 | 18 | Firstly we need to create an instance of the client with your application client credentials you have been given by Facebook 19 | when you set up your application. 20 | 21 |
client = FacebookOAuth::Client.new(
22 | :application_id => 'YOUR_APPLICATION_ID',
23 | :application_secret => 'YOUR_APP_SECRET_KEY',
24 | :callback => 'http://example.com/facebook/callback'
25 | )
26 |
27 | client.authorize_url
28 | => "https://graph.facebook.com/oauth/authorize?scope=SCOPE&client_id=ID&type=web_server&redirect_uri=CALLBACK"
29 |
30 |
31 | In your application your user would be redirected to Facebook to authorize the application at this point. The code continues below assuming the user has authorized your application, facebook will return to your callback URL with a code parameter.
32 |
33 | access_token = client.authorize(:code => code)
34 |
35 | client.me.info # returns your user information
36 |
37 |
38 | Now if you keep hold of the access_token.token (usually in the database) for this user you won't need to re-authorize them next time. When you create an instance of the client you can just pass in the access token that you have stored.
39 |
40 | access_token = @user.access_token # assuming @user
41 |
42 | client = FacebookOAuth::Client.new(
43 | :application_id => 'YOUR_APPLICATION_ID',
44 | :application_secret => 'YOUR_APP_SECRET_KEY',
45 | :token => access_token
46 | )
47 |
48 | client.me.info # returns your user information
49 |
50 |
51 | h2. Supported objects
52 |
53 | * Me (a special object that represents the current authorized user)
54 |
55 | * Album
56 | * Event
57 | * Group
58 | * Link
59 | * Note
60 | * Page
61 | * Photo
62 | * Post
63 | * Status
64 | * User
65 | * Video
66 |
67 | You can access any object listed above in the same way via the API. For example:
68 |
69 | client.me.home # the authorized users news feed
70 | client.event('event_id').attending # event attendees
71 | client.group('group_id').members # group members
72 | client.photo('photo_id').comments # comments on a photo
73 |
74 |
75 | Check out the "Facebook API Reference":http://developers.facebook.com/docs/reference/api/ to see what methods are available.
76 |
77 | h2. Publishing options
78 |
79 | In order to publish content to a user you need to have the correct permissions. For example, to publish to a users wall you need the publish_stream permission. You specify the permissions you want to have for the authorizing user when you generate the authorize url like this:
80 |
81 | client.authorize_url(:scope => 'publish_stream')
82 |
83 | The scope is a comma-separated list of permissions. See the "Facebook Permissions Documentation":http://developers.facebook.com/docs/authentication/permissions for more information.
84 |
85 | With the correct permissions you can now post to a users wall like this:
86 |
87 | client.me.feed(:create, :message => 'Testing writing to your wall...')
88 |
89 | Other examples include:
90 |
91 | client.event('event_id').attending(:create) # the user is attending the event
92 | client.post('post_id').comments(:create, :message => 'my comment') # comment on a post
93 | client.user('user_id').albums(:create, :name => 'my album', :message => 'cool pictures') # create an album
94 |
95 |
96 | For a full list of supported publishing objects and parameters check out the "Facebook API Documentation":http://developers.facebook.com/docs/api under "Publishing to Facebook."
97 |
98 | NOTE: I still have to implement the upload a photo method. Also if you can think of a better syntax for the create methods let me know!
--------------------------------------------------------------------------------
/facebook_oauth.gemspec:
--------------------------------------------------------------------------------
1 | # -*- encoding: utf-8 -*-
2 |
3 | Gem::Specification.new do |s|
4 | s.name = %q{facebook_oauth}
5 | s.version = "0.3.0"
6 |
7 | s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8 | s.authors = ["Richard Taylor"]
9 | s.date = %q{2011-11-03}
10 | s.description = %q{facebook_oauth is a Ruby client library for the Facebook OAuth Graph API}
11 | s.email = %q{moomerman@gmail.com}
12 | s.files = ["LICENSE", "README.textile","lib/facebook_oauth.rb"] + Dir.glob('lib/facebook_oauth/*.rb')
13 | s.has_rdoc = false
14 | s.homepage = %q{http://github.com/moomerman/facebook_oauth}
15 | s.rdoc_options = ["--inline-source", "--charset=UTF-8"]
16 | s.require_paths = ["lib"]
17 | s.rubyforge_project = %q{facebook_oauth}
18 | s.rubygems_version = %q{1.3.1}
19 | s.summary = %q{facebook_oauth is a Ruby client library for the Facebook OAuth Graph API}
20 |
21 | if s.respond_to? :specification_version then
22 | current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
23 | s.specification_version = 2
24 |
25 | if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
26 | s.add_runtime_dependency(%q