Photo and Album - nov/fb_graph GitHub Wiki

Photo and Album

Uploading

Without album context

Call FbGraph::User#photo!.
It upload a photo to the default album of the application.
Facebook will create an album named “_APPLICATION_NAME_’s Album” if not exist.

me = FbGraph::User.me(ACCESS_TOKEN)
me.photo!(
  :source => File.new('/Users/nov/Desktop/nov.gif', 'rb'), # 'rb' is needed only on windows
  :message => 'Hello, where is photo?'
)

With album context

You can also specify an album to upload the photo.
Call FbGraph::Album#photo! in this case.

me = FbGraph::User.me(ACCESS_TOKEN)
album = me.albums.first
album.photo!(
  :source => File.new(File.join(File.dirname(__FILE__), 'fb_graph.png'), 'rb'), # 'rb' is needed only on windows
  :message => 'FbGraph Test'
)

Via URL

You can also post a photo hosted out of facebook.com domain.
You don’t need to “upload” actual files in this case.

me.photo!(
  :url => 'http://matake.jp/images/zengardens.jpg',
  :message => 'Upload Photo via URL'
)

Tagging

Upload with tags

:tags option is supported both in FbGraph::User#photo! and FbGraph::Album#photo!
If you know the identifier (uid or username) of the tagged user, put :id => _uid_or_username_ to Tag.new.
If an user identifier is specified, Facebook will automatically link the tag to the user’s profile page.

## Upload a photo with tags
tags = [
  FbGraph::Tag.new(
    :name => "without profile link",
    :x => 0,
    :y => 95
  ),
  FbGraph::Tag.new(
    :id => 579612276,
    :name => "with Facebook profile link",
    :x => 5,
    :y => 0
  )
]
FbGraph::User.me(ACCESS_TOKEN).photo!(
  :source => File.new(File.join(File.dirname(__FILE__), 'fb_graph.png'), 'rb'),
  :message => 'FbGraph Test',
  :tags => tags
)

Add a tag to an existing photo

photo = FbGraph::Photo.new('10150177635467277', :access_token => ACCESS_TOKEN).fetch
photo.tag!(
  :to => 'matake',
  :x => 50,
  :y => 50
)

Profile Pictures

FbGraph::User#picture returns current profile picture URL of the user.
If you want all pictures in the user’s “Profile Pictures” album, do like this.

album = FbGraph::User.me(ACCESS_TOKEN).albums.detect do |album|
  album.type == 'profile'
end
profile_pictures = album.photos
⚠️ **GitHub.com Fallback** ⚠️