http - 为什么我的 Twitter OAuth API 调用更新状态失败,但其他调用有效?

标签 http rest twitter

这是我用来验证身份验证的原始 HTTP 调用。它返回预期的响应:

GET /1/account/verify_credentials.xml HTTP/1.1
Authorization: OAuth oauth_token="12556442-pndSo1mf2i1ToPSbAyLH4qBBDHmtyutjbvMLckGER",oauth_consumer_key="ih75ityikrTdIwB9kQ",oauth_nonce="6wIbdfxL",oauth_signature_method="HMAC-SHA1",oauth_signature="7DUW5TLtntryndfhU5dSXARg%3D",oauth_version="1.0",oauth_timestamp="1267805254"
Host: api.twitter.com

这是我(尝试)进行的调用,旨在更新用户状态:

POST /1/statuses/update.xml HTTP/1.1
Authorization: OAuth oauth_token="1252356242-pndSo1mf2i1ToPSfghfghfQoMLckGER",oauth_consumer_key="ih75i83BXdfhnfghnfgQ",oauth_nonce="CJ9dfgXs",oauth_signature_method="HMAC-SHA1",oauth_signature="bSD7aXUdfghdfghfghfghoU%3D",oauth_version="1.0",oauth_timestamp="1267235407"
Content-Type: application/x-www-form-urlencoded
Host: api.twitter.com
Content-Length: 11
Connection: Keep-Alive

status=blah

对于第二个请求,我从 Twitter 得到的响应如下:

HTTP/1.1 401 Unauthorized
Date: Fri, 05 Mar 2010 16:17:18 GMT
Server: hi
Status: 401 Unauthorized
WWW-Authenticate: Basic realm="Twitter API"
Content-Type: application/xml; charset=utf-8
Content-Length: 135
Cache-Control: no-cache, max-age=1800
Set-Cookie: guest_id=12672352252251; path=/
Set-Cookie: _twitter_sess=BAh7CDoPY3JlYXRlZF9hdGsdgsdhdrhvdrthvdthd0%250ANDdkZTEyZjczZTY3ZGE4YmQ5IgpmbGFzaElDOidBY3Rpb25Db250cm9sbGVy%250AOjpGbGFzaDo6Rmxhc2hIYXNoewAGOgpAdXNlZHsA--0eb657ba0esdrvthdtdtgcdrtgc0ece8f1460; domain=.twitter.com; path=/
Expires: Fri, 05 Mar 2010 16:47:17 GMT
Vary: Accept-Encoding
Connection: close

<?xml version="1.0" encoding="UTF-8"?>
<hash>
  <request>/1/statuses/update.xml</request>
  <error>Incorrect signature</error>
</hash>

知道哪里出了问题吗?

  • 请注意,OAuth token 和其他内容当然已被加密。

最佳答案

已解决:

尽管我必须将此调用设为 POST 请求,但实际参数不能在 POST 正文中。我将状态变量放在请求的查询字符串中,它工作正常。

关于http - 为什么我的 Twitter OAuth API 调用更新状态失败,但其他调用有效?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2388222/

相关文章:

javascript - 使用 javascript 从 iframe src 读取 http 响应

node.js - Angular 生产错误 : Property does not exist on type 'object'

javascript - 在 Node.js/Express 中,如何自动将此 header 添加到每个 "render"响应中?

Node.js 使用选项(http 或 https)直接请求 URL

javascript - 小数点四舍五入 JavaScript

java - 为什么需要返回一个 Response 对象而不是 String 对象到 java 中的 http 请求?

javascript - Twitter 提要不显示所有内容,它只是一个链接

c# - Twitter API - OOB 流

url - 使用JQuery获取Twitter个人资料图片网址

json - 使用 REST API 删除本地/客户端对象的常用方法是什么?