【发布时间】:2013-12-19 20:42:46
【问题描述】:
我们正在尝试使用 ColdFusion 9 通过其 API v. 1.1 向 Twitter 发布更新,但尽管一切看起来应该可以正常工作,但我们仍会收到 401“未经授权”错误。任何帮助将不胜感激!
在这里回顾以前的帖子强化了我们所做的一切都是正确的信念,但也许有一些假设我们遗漏了。
以下三种方法都不适合我们(更新在表单字段中;更新在正文字段中;更新是 URL 的一部分。):
<cfhttp url="https://api.twitter.com/1.1/statuses/update.json" method="POST" throwonerror="yes">
<cfhttpparam type="header" name="Authorization" value="OAuth oauth_consumer_key="vAA11oLz0R7kigH0iXwjQ", oauth_nonce="3D18D32A07048D54724AA0F304E83CFF", oauth_signature="TaEA6Ip9AJ07QKTxcWWT4fzPNpA%3D", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1386088450", oauth_token="82684171-ptqIw8uOz0KNwBEL4AO7ue8DpzciWSNKvUqDoAf8p", oauth_version="1.0" ">
<cfhttpparam type="header" name="Content-Type" value="application/x-www-form-urlencoded">
<cfhttpparam type="formfield" name="status" value="HelloWorld" encoded="yes">
</cfhttp>
<cfhttp url="https://api.twitter.com/1.1/statuses/update.json" method="POST" throwonerror="yes">
<cfhttpparam type="header" name="Authorization" value="OAuth oauth_consumer_key="vAA11oLz0R7kigH0iXwjQ", oauth_nonce="3D18D32A07048D54724AA0F304E83CFF", oauth_signature="TaEA6Ip9AJ07QKTxcWWT4fzPNpA%3D", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1386088450", oauth_token="82684171-ptqIw8uOz0KNwBEL4AO7ue8DpzciWSNKvUqDoAf8p", oauth_version="1.0" ">
<cfhttpparam type="header" name="Content-Type" value="application/x-www-form-urlencoded">
<cfhttpparam type="body" value="status=HelloWorld" encoded="yes">
</cfhttp>
<cfhttp url="https://api.twitter.com/1.1/statuses/update.json?status=HelloWorld" method="POST" throwonerror="yes">
<cfhttpparam type="header" name="Authorization" value="OAuth oauth_consumer_key="vAA11oLz0R7kigH0iXwjQ", oauth_nonce="3D18D32A07048D54724AA0F304E83CFF", oauth_signature="TaEA6Ip9AJ07QKTxcWWT4fzPNpA%3D", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1386088450", oauth_token="82684171-ptqIw8uOz0KNwBEL4AO7ue8DpzciWSNKvUqDoAf8p", oauth_version="1.0" ">
<cfhttpparam type="header" name="Content-Type" value="application/x-www-form-urlencoded">
</cfhttp>
Twitter 帐户已授予此应用的读/写访问权限。我们正在根据 https://dev.twitter.com/docs/auth/authorizing-request 和 https://dev.twitter.com/docs/auth/creating-signature 的指示进行编码,我们已经看到了这些 SO 页面:ColdFusion Twitter API Bad Request、ColdFusion Post To Twitter Authentication Error、Twitter, oauth and coldfusion、Twitter API status update not working when updating to v1.1,我们尝试了 Apigee。
我们正在使用我们的访问令牌及其秘密来生成签名。我们在这里缺少什么?这应该是发布更新的单步过程,还是我们需要在尝试发布之前进行身份验证或授权的步骤? Twitter 开发网站上的 OAuth 工具选项卡会生成与我们的 ColdFusion 脚本生成的相同的标头等。
-肯
【问题讨论】:
-
monkehtweet 是肯的方式。下载并使用它...它会节省你拉头发的时间。同时你不应该在你的示例代码中发布实际的密钥和签名,除非你想邀请邪恶的黑客:)
-
嗨,马克 - 密钥和令牌已重置,所以不用担心。我们确实尝试了monkeyhtweet,但发现更令人毛骨悚然,而且这条路线对于发布推文的单一目的来说似乎要简单得多。
标签: twitter coldfusion twitter-oauth coldfusion-9 http-status-code-401