facebook_oauth 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.textile +23 -6
- data/lib/facebook_oauth/client.rb +3 -3
- data/lib/facebook_oauth/objects.rb +7 -4
- metadata +4 -4
data/README.textile
CHANGED
@@ -8,6 +8,8 @@ h2. Using the gem
|
|
8
8
|
|
9
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
10
|
|
11
|
+
See "http://facebook-oauth.heroku.com/":http://facebook-oauth.heroku.com/ for a full integration example.
|
12
|
+
|
11
13
|
h2. Authorized request example
|
12
14
|
|
13
15
|
To use the full power of the Facebook API you need to authorize your application and a valid Facebook user via OAuth.
|
@@ -33,20 +35,19 @@ In your application your user would be redirected to Facebook to authorize the a
|
|
33
35
|
client.me.info # returns your user information
|
34
36
|
</code></pre>
|
35
37
|
|
36
|
-
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
|
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.
|
37
39
|
|
38
40
|
<pre><code>access_token = @user.access_token # assuming @user
|
41
|
+
|
39
42
|
client = FacebookOAuth::Client.new(
|
40
43
|
:application_id => 'YOUR_APPLICATION_ID',
|
41
44
|
:application_secret => 'YOUR_APP_SECRET_KEY',
|
42
|
-
:callback => 'http://example.com/facebook/callback',
|
43
45
|
:token => access_token
|
44
46
|
)
|
45
47
|
|
46
48
|
client.me.info # returns your user information
|
47
49
|
</code></pre>
|
48
50
|
|
49
|
-
|
50
51
|
h2. Supported objects
|
51
52
|
|
52
53
|
* Me (a special object that represents the current authorized user)
|
@@ -63,8 +64,24 @@ h2. Supported objects
|
|
63
64
|
* User
|
64
65
|
* Video
|
65
66
|
|
66
|
-
You can access any object listed above in the same way via the API. For example
|
67
|
+
You can access any object listed above in the same way via the API. For example:
|
68
|
+
|
69
|
+
<pre><code>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
|
+
</code></pre>
|
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 <code>publish_stream</code> permission. You specify the permissions you want to have for the authorizing user when you generate the authorize url like this:
|
80
|
+
|
81
|
+
<pre><code>client.authorize_url(:scope => 'publish_stream')</code></pre>
|
82
|
+
|
83
|
+
The scope is a comma-separated list of permissions. See the "Facebook Permissions page":http://developers.facebook.com/docs/authentication/permissions for more information.
|
67
84
|
|
68
|
-
|
85
|
+
With the correct permissions you can now post to a users wall like this:
|
69
86
|
|
70
|
-
|
87
|
+
<pre><code>client.me.feed(:create, :message => 'Testing writing to your wall...')</pre></code>
|
@@ -11,7 +11,7 @@ module FacebookOAuth
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def authorize_url(options = {})
|
14
|
-
options[:scope] ||= '
|
14
|
+
options[:scope] ||= 'offline_access,publish_stream'
|
15
15
|
consumer.web_server.authorize_url(
|
16
16
|
:redirect_uri => options[:callback] || @callback,
|
17
17
|
:scope => options[:scope]
|
@@ -45,8 +45,8 @@ module FacebookOAuth
|
|
45
45
|
JSON.parse(oauth_response)
|
46
46
|
end
|
47
47
|
|
48
|
-
def _post(url,
|
49
|
-
oauth_response = access_token.post(url,
|
48
|
+
def _post(url, params={}, headers={})
|
49
|
+
oauth_response = access_token.post(url, params, headers)
|
50
50
|
JSON.parse(oauth_response)
|
51
51
|
end
|
52
52
|
|
@@ -50,7 +50,7 @@ module FacebookOAuth
|
|
50
50
|
end
|
51
51
|
|
52
52
|
end
|
53
|
-
|
53
|
+
|
54
54
|
class FacebookObject
|
55
55
|
def initialize(oid, client)
|
56
56
|
@oid = oid
|
@@ -61,9 +61,12 @@ module FacebookOAuth
|
|
61
61
|
@client.send(:_get, @oid)
|
62
62
|
end
|
63
63
|
|
64
|
-
def method_missing(
|
65
|
-
|
66
|
-
|
64
|
+
def method_missing(method, *args)
|
65
|
+
if args.first and args.first == :create
|
66
|
+
@client.send(:_post, "/#{@oid}/#{method.to_s}", args.last)
|
67
|
+
else
|
68
|
+
@client.send(:_get, "/#{@oid}/#{method.to_s}")
|
69
|
+
end
|
67
70
|
end
|
68
71
|
|
69
72
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: facebook_oauth
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Richard Taylor
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-05-
|
12
|
+
date: 2010-05-07 00:00:00 +01:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -65,7 +65,7 @@ dependencies:
|
|
65
65
|
- !ruby/object:Gem::Version
|
66
66
|
version: "0"
|
67
67
|
version:
|
68
|
-
description: facebook_oauth is a Ruby client library for
|
68
|
+
description: facebook_oauth is a Ruby client library for the Facebook OAuth Graph API
|
69
69
|
email: moomerman@gmail.com
|
70
70
|
executables: []
|
71
71
|
|
@@ -107,6 +107,6 @@ rubyforge_project: facebook_oauth
|
|
107
107
|
rubygems_version: 1.3.5
|
108
108
|
signing_key:
|
109
109
|
specification_version: 2
|
110
|
-
summary: facebook_oauth is a Ruby client library for
|
110
|
+
summary: facebook_oauth is a Ruby client library for the Facebook OAuth Graph API
|
111
111
|
test_files: []
|
112
112
|
|