我正在使用OmniAuth为我的用户收集Oauth/OAuth2凭据,然后以他们的名义发布到这些服务的Rails应用程序。Ruby on Rails - OAuth 2多部分发布(上传至Facebook或Soundcloud)
创建简单的帖子来更新状态饲料工作很好..现在我需要上传文件。 Facebook说:“要发布照片,请发送带有照片文件附件的POST请求作为multipart/form-data。” http://developers.facebook.com/docs/reference/api/photo/
所以这是我想做的事:
我已经实现了这里的模块:Ruby: How to post a file via HTTP as multipart/form-data?获得头和数据...
if appearance.post.post_attachment_content_type.to_s.include?('image')
fbpost = "https://graph.facebook.com/me/photos"
data, headers = Multipart::Post.prepare_query("title" => appearance.post.post_attachment_file_name , "document" => File.read(appearance.post.post_attachment.path))
paramsarray = {:source=>data, :message=> appearance.post.content}
response = access_token.request(:post, fbpost, paramsarray, headers)
appearance.result = response
appearance.save
end
我,但我得到一个的OAuth2 :: HTTPError - HTTP 400错误
任何帮助将是令人难以置信的...正如我看到这些信息也将需要上传文件到SoundCloud也。
感谢,
马克