400 error when submitting tumblr post (ruby on rails)
-
04-10-2019 - |
Question
I am having a bit of an issue with getting tumblr working within a rails app.
This is the snippet of code which results in a 400 error (meaning that there was an incorrect parameter)
@postcontent = @post.content.gsub(/<\/?[^>]*>/, "") post = Tumblr::Post.create(:email => 'valid@email', :password => 'mypassword', :type => 'video', :embed
=> @post.video_html, :caption => @postcontent)
I have checked the API docs and checked my code and code content being rendered, and it still does not want to work.
The funny thing is that it worked previously. It was working about a week ago. Has something changed with tumblr?
Update: I have also posted this on github in the issues section, and discovered that it's only with one of my posts that this method is not working, AND I have sent it over to the good people at tumblr. Has anyone else had this issue?
Solution
I HAVE WORKED THIS OUT ...
for anyone finding difficulty in this here is a solution. Firstly, there was an error with the gem itself. Some code needs to be modified. Check out this version of the gem: http://github.com/mindreframer/tumblr
Secondly, as Tumblr allows html, I am calling sanitize within the controller to make my content nicely formatted and clean.
class PostsController < ApplicationController
include ActionView::Helpers::TextHelper
include ActionView::Helpers::SanitizeHelper
def tumblrsubmit
tumblruser = Tumblr::User.new('valid@email', 'validpass', false)
Tumblr.blog = 'blogname'
@post = Post.find(params[:id])
begin
unless @post.movie_id.nil? #checks if there is a movie ID
@tags = @post.tags.join(', ')
post = Tumblr::Post.create(tumblruser,
:type => 'video',
:embed => @post.video_html , #fetches the stored embed code
:caption => "Read Full Article & More at: <a href='http://www.mywebsite.com/posts/#{@post.slug}'>#{@post.title}</a> <p> </p>#{ActionController::Base.helpers.sanitize(@post.content)}",
:slug => @post.slug,
:tags => @tags )
else
post = Tumblr::Post.create(:tumblruser, :type => 'regular', :title => @post.title, :body => ActionController::Base.helpers.sanitize(@post.content), :slug => @post.slug)
end
@post.update_attributes(:tumbler_id => "#{post}") #updates the database with the new tumblr post id
flash[:notice] = "Successfully sent <strong>#{@post.title}</strong> to tumblr. with post id = #{post}"
rescue
flash[:error] = "You are unable to post <strong>#{@post.title}</strong> to tumblr at this time"
end
redirect_to :back
end
end
I know this seems like alot, but it does the job. Hope this helps anyone else out there.
Cheers, Matenia