Module: FbGraph::Connections::Albums
- Included in:
- Application, Page, User
- Defined in:
- lib/fb_graph/connections/albums.rb
Overview
Authentication
-
Access token is required to fetch/create albums.
-
“publish_stream” permissin is required to create new album.
Connected with
-
FbGraph::Application
-
FbGraph::USer
-
FbGraph::Page
Example
Fetch albums
me = FbGraph::User.me(ACCESS_TOKEN)
me.albums
# => Array of FbGraph::Album
page = FbGraph::Page.new('fb_graph')
page.albums
# => Array of FbGraph::Album
Create an album
me = FbGraph::User.me(ACCESS_TOKEN)
album = me.album!(
:name => 'FbGraph test',
:message => 'hello world!',
:description => 'hello world!'
)
page = FbGraph::Page.new('fb_graph', :access_token => ACCESS_TOKEN)
album = page.album!(
:name => 'FbGraph test',
:message => 'hello world!',
:description => 'hello world!'
)
Notes
Attributes after created
Only attributes you specified are saved in the created album object. If you want to access any other attributes, you need to fetch the album info via Graph API.
me = FbGraph::User.me(ACCESS_TOKEN)
album = me.album!(
:name => 'FbGraph test',
:message => 'hello world!',
:description => 'hello world!'
)
album.name # => 'FbGraoh test'
album.from # => nil
album.created_time # => nil
album.fetch
album.from # => me
album.created_time # => Sun Sep 12 01:18:36 +0900 2010
Bug of Graph API
According facebook’s document, the key for description should be description both when fetching and creating, but actually you need to use message instead of description only when creating. It probably facebook’s bug, and it might be fixed suddenly. I highly recommend to send same value both as description and message when creating, then your code will work without any code change.
ref) developers.facebook.com/docs/reference/api/album
me = FbGraph::User.me(ACCESS_TOKEN)
album = me.album!(
:name => 'FbGraph test',
:message => 'hello world!',
:description => 'hello world!'
)
Instance Method Summary collapse
Instance Method Details
#album!(options = {}) ⇒ Object
88 89 90 91 92 93 |
# File 'lib/fb_graph/connections/albums.rb', line 88 def album!( = {}) album = post(.merge(:connection => 'albums')) Album.new(album.delete(:id), .merge(album).merge( :access_token => [:access_token] || self.access_token )) end |
#albums(options = {}) ⇒ Object
79 80 81 82 83 84 85 86 |
# File 'lib/fb_graph/connections/albums.rb', line 79 def albums( = {}) albums = self.connection(:albums, ) albums.map! do |album| Album.new(album.delete(:id), album.merge( :access_token => [:access_token] || self.access_token )) end end |