简体   繁体   English

Twitter API + OAuth:无法发送状态更新,收到 401

[英]Twitter API + OAuth: Can't send status updates, getting 401

I'm trying to use Twitter's API and OAuth to send status updates (new Tweets).我正在尝试使用 Twitter 的 API 和 OAuth 发送状态更新(新推文)。 I am using Shannon Whitley .NET code example http://www.voiceoftech.com/swhitley/?p=681 (as recommended on the Twitter API docs).我正在使用 Shannon Whitley .NET 代码示例http://www.voiceoftech.com/swhitley/?p=681 (如 Twitter API 文档中所推荐)。 I can read (GET) using OAuth just fine, however when I try to send a status update via http ://twitter.com/statuses/update.xml (using a POST), it returns a 401 with the following XML:我可以使用 OAuth 读取 (GET) 就好了,但是当我尝试通过 http://twitter.com/statuses/update.xml(使用 POST)发送状态更新时,它返回一个带有以下 XML 的 401:

<?xml version="1.0" encoding="UTF-8"?>
<hash>
  <request>/statuses/update.xml</request>
  <error>Read-only application cannot POST</error>
</hash>

I swear I have set up my application to use read and write, the authorise page at Twitter (http ://twitter.com/oauth/authorize) even says "The application TweeVerbs.com (Development) by would like the ability to access and update your data on Twitter."我发誓我已经将我的应用程序设置为使用读写,Twitter 上的授权页面 (http://twitter.com/oauth/authorize) 甚至说“应用程序 TweeVerbs.com(开发)希望能够访问并在 Twitter 上更新你的数据。”

Yet it's still saying "Read-only application cannot POST".然而它仍然说“只读应用程序不能发布”。 WTF!?卧槽!?

I have googled this error message until I was blue in the face.我在谷歌上搜索了这条错误信息,直到我脸色发青。 I found somewhere that said to add the querystring paremeter oauth_access_type=write to the redirect URL which goes to the Twitter authorise page which I have done, but it still gives me a 401.我发现某处说要将查询字符串参数oauth_access_type=write添加到重定向 URL,该 URL 转到我已经完成的 Twitter 授权页面,但它仍然给我 401。


If it helps, here is the data that is getting sent back and firth as per the OAuth workflow:如果有帮助,这里是根据 OAuth 工作流程发回和发送的数据:

Request Authorise Token:请求授权令牌:

http ://twitter.com/oauth/request_token?oauth_consumer_key=tViV8vAt4cqSKbGdPGWT7Q&oauth_nonce=2790042&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1244567068&oauth_version=1.0&oauth_signature=KzxcXN%2bQ0AJoAJ%2flQfzs8SLjC%2fQ%3d http://twitter.com/oauth/request_token?oauth_consumer_key=tViV8vAt4cqSKbGdPGWT7Q&oauth_nonce=2790042&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1244567068&oauth_timestamp=1244567068&oauth_timestamp=1244567068&oauth%2fj%2fj%2fj%2aqsl%2fj%aqsl%2fj%2fj%2fj%2fj%2fjqsl%2fj%2fj%2fj%2fj%2fj%2fj%2fj%2fj%2fj%2fj%2fj%2fj%2flzaql

Generated Authorize Redirect URL:生成的授权重定向 URL:

http ://twitter.com/oauth/authorize?oauth_token=EpyBg3nJGOmtmBjRUAsqqaGHARb2F2F2VcccqHkwio&oauth_access_type=write http://twitter.com/oauth/authorize?oauth_token=EpyBg3nJGOmtmBjRUAsqqaGHARb2F2F2VcccqHkwio&oauth_access_type=write

Authorise Screen Message: "The application TweeVerbs.com (Development) by would like the ability to access and update your data on Twitter. This application plans to use Twitter for logging you in in the future. Sign out if you want to connect to an account other than Sironfoot."授权屏幕消息: “应用程序 TweeVerbs.com(开发)希望能够访问和更新您在 Twitter 上的数据。此应用程序计划在将来使用 Twitter 来登录您。如果您想连接到Sironfoot 以外的帐户。”

Get Access Token:获取访问令牌:

http ://twitter.com/oauth/access_token?oauth_consumer_key=tViV8vAt4cqSKbGdPGWT7Q&oauth_nonce=2016804&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1244567166&oauth_token=EpyBg3nJGOmtmBjRUAsqqaGHARb2F2F2VcccqHkwio&oauth_version=1.0&oauth_signature=%2bEVQUxUPLT%2b%2bkfaG0Vq1YJZXcAw%3d HTTP://twitter.com/oauth/access_token oauth_consumer_key = tViV8vAt4cqSKbGdPGWT7Q&oauth_nonce = 2016804&oauth_signature_method = HMAC-SHA1&oauth_timestamp = 1244567166&组oauth_token = EpyBg3nJGOmtmBjRUAsqqaGHARb2F2F2VcccqHkwio&oauth_version = 1.0&oauth_signature =%2bEVQUxUPLT%2B%2bkfaG0Vq1YJZXcAw%3D

Status Update API call: URL - http ://twitter.com/statuses/update.xml POST data - oauth_consumer_key=tViV8vAt4cqSKbGdPGWT7Q&oauth_nonce=5707692&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1244567268&oauth_token=19130957-nb89DjZhjCAzcbHUa96yRWHqlQFQIJ0AKyXpqnHt1&oauth_version=1.0&status=HelloWorld&oauth_signature=WqA%2bWY0IxveeSJ7G3Ewy3whh1sE%3d状态更新API调用:URL - HTTP://twitter.com/statuses/update.xml POST数据- oauth_consumer_key = tViV8vAt4cqSKbGdPGWT7Q&oauth_nonce = 5707692&oauth_signature_method = HMAC-SHA1&oauth_timestamp = 1244567268&组oauth_token = 19130957-nb89DjZhjCAzcbHUa96yRWHqlQFQIJ0AKyXpqnHt1&oauth_version = 1.0&状态=的HelloWorld&oauth_signature = WQA%2bWY0IxveeSJ7G3Ewy3whh1sE%3D

I don't know what the problem was, but I deleted my Application registration on Twitter (You have to register apps in Twitter to get OAuth keys etc.), and then recreated it.我不知道问题出在哪里,但我删除了我在 Twitter 上的应用程序注册(您必须在 Twitter 中注册应用程序才能获取 OAuth 密钥等),然后重新创建它。 Now it works fine.现在它工作正常。 Weird, probably a problem with Twitter screwing up.奇怪,可能是 Twitter 搞砸的问题。

I'm also using Tweetsharp ( http://tweetsharp.com/ ), highly recommend it, it's got a nice fluent API.我也在使用 Tweetsharp ( http://tweetsharp.com/ ),强烈推荐它,它有一个很好的流畅的 API。 Note: switching over to Tweetsharp wasn't the fix, I had already switched over and had the same problem until I delete and recreated app registration on Twitter.注意:切换到 Tweetsharp 不是解决方案,我已经切换并遇到了同样的问题,直到我在 Twitter 上删除并重新创建应用程序注册。

If you authorized your application to access your Twitter account when the application was set in "read only access" mode and you get the "Read-only application cannot POST" error after changing the application settings to be "read and write access" then you have to revoke access to the application on https://twitter.com/settings/connections and then reauthorize it.如果您在应用程序设置为“只读访问”模式时授权应用程序访问您的 Twitter 帐户,并且在将应用程序设置更改为“读写访问”后收到“只读应用程序无法发布”错误,那么您必须在https://twitter.com/settings/connections上撤销对应用程序的访问,然后重新授权。 The "read only" access_token tends to be sticky until you revoke it. “只读” access_token 在您撤销它之前往往是粘性的。

Hope this helps.希望这可以帮助。

plus also see if your system's CLOCK is synched with internet;另外还要查看您系统的时钟是否与互联网同步; on windows you can do it by adjusting date time settings在 Windows 上,您可以通过调整日期时间设置来实现

because if you CLOCK is not synched you will get 401 unauthorized exception;因为如果您的 CLOCK 未同步,您将收到 401 未经授权的异常; best of luck cheers祝你好运

I've dont that several times now, without succes, I'm getting a 401 exception while requesting an acces token from twitter.我现在没有多次这样做,但没有成功,我在从 twitter 请求访问令牌时收到 401 异常。

I'm using Tweetsharp as well as you.我和你一样在使用 Tweetsharp。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM