Tumblr OAuth图片帖子给了我401 /“无效的OAuth凭证”。 [英] Tumblr OAuth image post gives me 401/"Invalid OAuth credentials"

查看:106
本文介绍了Tumblr OAuth图片帖子给了我401 /“无效的OAuth凭证”。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个iOS应用程序可以将图像发布到多个服务,包括twitter,我正在尝试将该支持扩展到tumblr。我已经为OAuth 1.0a标头逻辑调整了一些开源代码,它的运行良好,足以成功实现twitter + twitpic和tumblr的身份验证。但是tumblr的图片帖子失败,状态为401,字符串响应无效OAuth凭证



为简化起见,我的唯一多部分部分是帖子类型和图像数据。 / p>

所以我的简单POST就是 http:// www .tumblr.com / api / write ,签名基本字符串(粗略地说,因为我已经编辑了我的消费者密钥和令牌,并添加了换行符以便于阅读):

  POST& http%3A%2F%2Fwww.tumblr.com%2Fapi%2Fwrite& 
oauth_consumer_key%3Dxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx%26
oauth_nonce%3D71edd7a1224463a7e1723bb7b568060b4d69deb6%26
oauth_signature_method%3DHMAC-SHA1%26
oauth_timestamp%3D1297678418%26
组oauth_token%3Dxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx%26
oauth_version%3D1.0%26
类型%3Dphoto

我的oauth标题是(再次,为便于阅读添加了换行符):

 授权:OAuth realm =http://www.tumblr.com/, 
oauth_consumer_key =xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx,
oauth_signature_method =HMAC-SHA1,
oauth_timestamp =1296445530,
oauth_nonce =71edd7a1224463a7e1723bb7b568060b4d69deb6,
oauth_version =1.0 ,
oauth_token =xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx,
oauth_signature =fWuli4eO3qVehfdeFzZN%2FDNYpFk%3D

我添加的唯一其他标题是Content-Type(multipart / form-data) &安培; Content-Length和消息正文只是:

   -  my_sorta_unique_boundary_string 
Content-Disposition:form-data; name =type

photo
--my_sorta_unique_boundary_string
Content-Disposition:form-data; name =data
Content-Type:image / jpg
Content-Transfer-Encoding:binary

...(图片数据)...
- -my_sorta_unique_boundary_string--

任何人都可以告诉我我的签名基本字符串是否有问题或auth标题,或者是否有一些让tumblr oauth帖子起作用的技巧?

解决方案

我的OAuth实现存在完全相同的问题在Silverlight中 - 我已经实现了API的其余部分而没有任何问题,如果您不使用OAuth并且只是发送电子邮件/密码标头,这种方法也适用。



<但是Arvin的帖子只是向我展示了这个问题,他在其OAuth中包含了其他非文件字段。我刚刚对我的帖子做了同样的事情,所以他们是多部分形式的身体,但也被添加到OAuth sig - 现在我上传照片帖子没有问题!


I've got an iOS app thats posts images to several services, including twitter and I'm trying to extend that support to tumblr. I've adapted some open source code for the OAuth 1.0a header logic and its working well enough to be successful for twitter + twitpic and for tumblr's authentication. However image posts to tumblr are failing with status 401 and string response "Invalid OAuth credentials"

To simplify, my only multipart sections are the post type and the image data.

So my simple POST is to http://www.tumblr.com/api/write, the signature base string is (roughly, as I’ve redacted my consumer key and token, and linebreaks added for readability):

POST&http%3A%2F%2Fwww.tumblr.com%2Fapi%2Fwrite&
oauth_consumer_key%3Dxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx%26
oauth_nonce%3D71edd7a1224463a7e1723bb7b568060b4d69deb6%26
oauth_signature_method%3DHMAC-SHA1%26
oauth_timestamp%3D1297678418%26
oauth_token%3Dxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx%26
oauth_version%3D1.0%26
type%3Dphoto

my oauth header is (again, linebreaks added here for readability):

Authorization: OAuth realm="http://www.tumblr.com/",
oauth_consumer_key="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
oauth_signature_method="HMAC-SHA1",
oauth_timestamp="1296445530",
oauth_nonce="71edd7a1224463a7e1723bb7b568060b4d69deb6",
oauth_version="1.0",
oauth_token="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
oauth_signature="fWuli4eO3qVehfdeFzZN%2FDNYpFk%3D"

the only other headers I’m adding are Content-Type (multipart/form-data) & Content-Length, and the message body is just:

--my_sorta_unique_boundary_string
Content-Disposition: form-data; name="type"

photo
--my_sorta_unique_boundary_string
Content-Disposition: form-data; name="data"
Content-Type: image/jpg
Content-Transfer-Encoding: binary

... (image data) ...
--my_sorta_unique_boundary_string--

Can anyone tell me if I’ve done something wrong with my signature base string or auth header, or if there's some trick for getting tumblr oauth posts to work?

解决方案

Having exactly the same problem with my OAuth implementation in Silverlight - I've implemented the rest of the API without an issue, and this method works if you don't use OAuth and just send email/password headers as well.

Arvin's post just showed me the issue though, he's including the other non-file fields in his OAuth. I just did the same to my post, so they were in the multi-part form body but also being added to the OAuth sig - and now I'm uploading photo posts without a problem!

这篇关于Tumblr OAuth图片帖子给了我401 /“无效的OAuth凭证”。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆