Uploading photo from server to facebook

I have a facebook canvas application and I want to upload a file from my server to the user's wall.

Facebook says that a form should be created, this is what I did:

 <form action="https://graph.facebook.com/me/photos?access_token=<%= @access_token %>" method="post" enctype="multipart/form-data">
        <input name="source" type="hidden" value="https://young-water-9853.herokuapp.com/images/1.jpg" />
        <input name="commit" type="submit" value="Upload photo" class="cupid-green" />
 </form>

This is the error I received:

{ "error": { "message": "(#324) Requires upload file", "type": "OAuthException" } }

How can I make it work?

Solution:

This is the action I am using to post an image to the wall:

get '/post_photo' do 
  RestClient.post 'https://graph.facebook.com/me/photos', :source => open('http://i52.tinypic.com/313jaxd.jpg'), :access_token => ACCESS_TOKEN
  redirect '/'
end

Answers


The source parameter needs to be a file object, not a url. If the user was uploading a file from their machine:

 <form action="https://graph.facebook.com/me/photos?access_token=<%= @access_token %>" method="post" enctype="multipart/form-data">
        <input name="source" type="file" />
        <input name="commit" type="submit" value="Upload photo" class="cupid-green" />
 </form>

Or if you wanted the user to upload a predefined image, you'd take care of that server-side. The rest_client gem looks like an ideal solution for this:

require 'rest_client'
RestClient.post 'https://graph.facebook.com/me/photos', :source => File.new('/path/to/your/file'), :access_token => YOUR_ACCESS_TOKEN

Need Your Help

Recovering Database after deleting .ldf file

sql sql-server database data-recovery

I have deleted the .ldf file. But after that I am unable to recover database.

Signed right shift = strange result?

c undefined-behavior endianness sign-extension

I was helping someone with their homework and ran into this strange issue. The problem is to write a function that reverses the order of bytes of a signed integer(That's how the function was specif...