Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to post images: HTTP 401 Unauthorized #23

Open
zachfeldman opened this issue Sep 26, 2013 · 30 comments
Open

Unable to post images: HTTP 401 Unauthorized #23

zachfeldman opened this issue Sep 26, 2013 · 30 comments
Labels

Comments

@zachfeldman
Copy link

I am unable to post images using the client, but am able to post text.

Using the gem entirely outside of the context of my Rails application, I made many successful text posts, i.e.:

client.text("mygreatblog.tumblr.com", {title: "test", body: "test even more"})
=> {"id"=>62354560747}

but when I attempt to make a photo post which I've been doing successfully for months, I get the following:

client.photo("mygreatblog.tumblr.com", { source: ["http://static.ddmcdn.com/gif/great-white-shark-1.jpg"], state: "publish"})
=> {"status"=>401, "msg"=>"Not Authorized"}

I've tried this with a few other blogs/oauth tokens. This one was just authorized/generated today (fake blog url). Any ideas?

@codingjester
Copy link

I didn't look too hard into the "why" here (which I'll do) but switch your syntax around to this:

client.photo('blog.tumblr.com', :source => "http://url.to/photo.jpg", :state => "publish")

Most likely something is happening to your parameters so they don't get signed properly and it's 401ing.

@zachfeldman
Copy link
Author

Tried switching the syntax and that didn't fix it. Still getting a 401.

@zachfeldman
Copy link
Author

Is there anyway to see exactly what kind of request is getting sent through the gem? Like a debug mode of some kind?

@codingjester
Copy link

Nope no debug mode per-say, but I'm assuming you've also gone through the 3-legged oauth step and have your access tokens. Could you post more code with exactly what you are doing? Just don't include your tokens in the post please :)

@zachfeldman
Copy link
Author

require 'tumblr_client'

Tumblr.configure do |config|
  config.consumer_key = api_key
  config.consumer_secret = secret
  config.oauth_token = my_token
  config.oauth_token_secret = my_secret
end

client = Tumblr::Client.new

#require the above in IRB, then...
client.text("myblog.tumblr.com", {title: "test", body: "test even more"})
=>{"id"=>62355755631}

client.photo("funtesting.tumblr.com", :source => ["http://static.ddmcdn.com/gif/great-white-shark-1.jpg"], :state => "publish")
=>{"status"=>401, "msg"=>"Not Authorized"}

@zachfeldman
Copy link
Author

Yes, I've gone through the oauth step. Like I said, posting text works just fine - the problem is with posting photos.

@codingjester
Copy link

And you have access to "funtesting.tumblr.com", as in, it's one of your blogs?

@codingjester
Copy link

Oh, also if you could toss in your version of ruby that'd help :)

@codingjester
Copy link

Ah figured it out. remove the [] around "source" and it'll upload. We must be doing something wrong with how we hand off the parameters to the oauth lib. Thanks for the report :)

@zachfeldman
Copy link
Author

I definitely do! Didn't mean to put that in the code actually haha. I just signed up and oauthed it yesterday.

I'm running 2.0.0-p247.

@zachfeldman
Copy link
Author

Ah yes, it works with one photo. But what if I wanted to upload many photos?

@zachfeldman
Copy link
Author

In the past, giving it an array allowed me to do that if I remember correctly!

@codingjester
Copy link

well, therein lies the bug ;) I'll see if I can get this fixed and deployed out for you sometime today!

@zachfeldman
Copy link
Author

I still get a 401 if I try to upload many:

client.photo("funtesting.tumblr.com", :source => ["http://static.ddmcdn.com/gif/great-white-shark-1.jpg","http://images.nationalgeographic.com/wpf/media-live/photos/000/005/cache/great-white-shark_559_600x450.jpg"], :state => "publish")

@zachfeldman
Copy link
Author

Thanks @codingjester !!

@codingjester
Copy link

Hey @zachfeldman I figured out the bug. It looks like SimpleOAuth is double encoding parameters that have a [ or a ] in their parameter name and we require that due to the way we require source parameters to be like so:

source[0]=blah&source[1]=blah

So I'm going to close this and file a bug against the client.

@zachfeldman
Copy link
Author

Cool @codingjester , can you link me to the issue? Obviously need to find the resolution at some point so it would be great to track it. Thanks for looking into it!

@ivanovv
Copy link

ivanovv commented May 14, 2014

Why close this issue? If there is a bug in a 3rd party lib, it's not a reason to close an issue, imo. The gem doesn't work and an open issue should reflect that.

@ivanovv
Copy link

ivanovv commented May 14, 2014

I've also checked the issues of SimpleOAuth https://github.com/laserlemon/simple_oauth/issues and didn't see anything posted by you.

@codingjester
Copy link

You're right @ivanovv I must have forgot or got distracted. Thanks for calling me out.

@codingjester codingjester reopened this May 14, 2014
@ivanovv
Copy link

ivanovv commented May 14, 2014

Great!
I wonder if this simple_oauth issue has anything to do with our problem.

@codingjester
Copy link

@ivanovv interesting :) I'll pursue this during this weekend or the week. Thanks :)

@persocon
Copy link

👍 😢

@persocon
Copy link

persocon commented Jun 8, 2014

@codingjester no fix or workaround yet? :/ the simple_oauth issues didn't listed anything about tho :(

@ivanovv
Copy link

ivanovv commented Jul 12, 2014

as a possible workaround one can use :data => [], works for me with these versions

simple_oauth (0.2.0)
faraday (0.9.0)
faraday_middleware (0.9.1)

@codingjester
Copy link

@ivanovv interesting. I'll take some time this week and start cleaning something like this out. Thanks for the way to work around it. @persocon sorry for taking so long on this.

@zachfeldman
Copy link
Author

This issue will have its one year birthday in 24 days!

🍰

@codingjester
Copy link

Blah i know @zachfeldman Terrible of me to let it languish as such.

@sshao
Copy link

sshao commented Dec 24, 2014

Is uploading an array through the source parameter actually allowed by the API? The documentation for photo posts says that source is of type String, suggesting that you can only provide a single source -- which would be consistent with posting through the actual Tumblr Dashboard (it only allows one image to be uploaded from a URL).

On the other hand, the docs list that data is of type Array, so @ivanovv's suggestion works -- but only with actual image file uploads, not with image URLs. At least, I personally couldn't get it to work with URLs.

@zachfeldman
Copy link
Author

Looks like it'll be another few years before this issues gets closed lol, for now I'm unsubscribing to notifications...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants