我正在开发一个 Rails 应用程序,它使用 OmniAuth 为我的用户收集 Oauth/OAuth2 凭据,然后代表他们发布到这些服务。
创建简单的帖子来更新状态提要效果很好。现在我需要上传文件了。Facebook 说“要发布照片,请发出带有照片文件附件作为 multipart/form-data 的 POST 请求。” 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 也需要此信息。
谢谢,
标记