Image Uploading to facebook and tagging friends

For uploading and tagging the friends on Facebook in Ruby on Rails , we need a gem named “fb-graph”. Which will provide the api call for this functionality.

# @Params : params
# @Return : None
# @Purpose : To tag user on the image with comment and upload it to facebook
def create

# find the image from the image_id
@image = Image.find_by_id(params[:image_id])

# fetch the user details from the facebook
me =

#create the array of friends uid

friends = params[:friends].split(",")

tags = []

# looping through friends array

friends.each do |friend|

#creating a new tag object and add it to tag array

tags <<
:id => friend,
:name => "with Facebook profile link",
: x => 2*Random.rand(9),
:y => 9*Random.rand(2)

end # end of friends block

# uploading the image the friends tag!(
:url => @image.picture.url ,
:message => params[:message],
:tags => tags

flash[:success] = "Successfully uploaded and tagged the your friends."

redirect_to image_path(@image)

end # end of create action

Also you can pass the source file to upload the image instead of image url using!(
:source =>, 'fb_graph.png'), 'rb'),
:message => params[:message],
:tags => tags

For more information visit the site

Also you can checkout my running application at
Thanks for reading the post……. 🙂