简体   繁体   中英

Posting a photo to the Facebook Open Graph from Heroku, using RoR, FbGraph Gem, and S3

I am trying to allow a user to share a photo on his Facebook wall. I use Paperclip to store all of my app's photos on S3. So in the below example @photo.image.url is the S3 url of an image that I want to post in some_album. Using the fb_graph gem this is relatively easy on localhost. In my controller I have:

    the_photo = open(@photo.image.url)
    some_album.photo!(
      :access_token => access_token,
      :source => the_photo
    )

the_photo's class on localhost is "Tempfile".

On heroku things get tricky. Using the same code two (seemingly related) things happen. First, the_photo is class type "stringIO". Second when FbGraph posts to Facebook I get the following error:

FbGraph::InvalidRequest (OAuthException :: (#324) Requires upload file):

Heres a few bullet points of facts that might also help:

  • Heroku is a read only system, but apparently you can write to a Tempfile
  • I am on Rails 3.1.0
  • Ruby 1.9.2
  • Heroku Stack Bamboo-Miri

Any help/thoughts/work arounds/questions would be greatly appreciated.

I am not sure why this did the trick but this worked for me:

some_album.photo!(
  :access_token => access_token,
  :source => open(@photo.image.url)
)

as opposed to setting a variable photo_response = open(@photo.image.url).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM