0

首先,我的项目需要我制作自己的模块,所以我不能使用那里的各种包和产品。话虽如此,使用正确的令牌、consumer_key、c​​onsumer_secret 和 token_secret 变量,创建正确的基本签名字符串,从而从该字符串创建 OAuth 签名,通过我的 ColdFusion 模块获取 Twitter 数据没有问题。如果其中任何一个关闭,我什至无法获得 Twitter 数据。

所以知道我的变量是正确的,我仍然无法通过 ColdFusion 将简单的状态推文发布到我的 Twitter 帐户。每次我尝试都会收到相同的错误:“代码:32,消息:'无法验证你'”。因为我知道它不可能是变量,所以它必须是我通过 ColdFusion 发送 POST 的方式,但我不确定我做错了什么。以下是我用来提交 POST 的代码:

<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="#oauthStruct.oauth_consumer_key#", oauth_nonce="#oauthStruct.oauth_nonce#", oauth_signature="#oauthStruct.oauth_signature#", oauth_signature_method="#oauthStruct.oauth_signature_method#", oauth_timestamp="#oauthStruct.oauth_timestamp#", oauth_token="#oauthStruct.oauth_token#", oauth_version="#oauthStruct.oauth_version#"'>
    <cfhttpparam type="header" name="Content-Type" value="application/x-www-form-urlencoded">
    <cfhttpparam type="formfield" name="status" value="#oauthStruct.status#">
</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="#oauthStruct.oauth_consumer_key#", oauth_nonce="#oauthStruct.oauth_nonce#", oauth_signature="#oauthStruct.oauth_signature#", oauth_signature_method="#oauthStruct.oauth_signature_method#", oauth_timestamp="#oauthStruct.oauth_timestamp#", oauth_token="#oauthStruct.oauth_token#", oauth_version="#oauthStruct.oauth_version#"'>
        <cfhttpparam type="header" name="Content-Type" value="application/x-www-form-urlencoded">
        <cfhttpparam type="header" name="oauth_consumer_key" value="#oauthStruct.oauth_consumer_key#">
        <cfhttpparam type="header" name="oauth_nonce" value="#oauthStruct.oauth_nonce#">
        <cfhttpparam type="header" name="oauth_signature" value="#oauthStruct.oauth_signature#">
        <cfhttpparam type="header" name="oauth_signature_method" value="#oauthStruct.oauth_signature_method#">
        <cfhttpparam type="header" name="oauth_timestamp" value="#oauthStruct.oauth_timestamp#">
        <cfhttpparam type="header" name="oauth_token" value="#oauthStruct.oauth_token#">
        <cfhttpparam type="header" name="oauth_version" value="#oauthStruct.oauth_version#">
        <cfhttpparam type="body" value="#signature_string#">
    </cfhttp>

它仍然不起作用,同样的身份验证错误。还有其他想法吗?

4

1 回答 1

0

我想到了。为了让其他人能够理解这个过程是如何进行的,使用新的 API (1.1),这是您将状态更新发布到您的 Twitter 帐户的方式:

    <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="#oauthStruct.oauth_consumer_key#", oauth_nonce="#oauthStruct.oauth_nonce#", oauth_signature="#oauthStruct.oauth_signature#", oauth_signature_method="#oauthStruct.oauth_signature_method#", oauth_timestamp="#oauthStruct.oauth_timestamp#", oauth_token="#oauthStruct.oauth_token#", oauth_version="#oauthStruct.oauth_version#"'>
        <cfhttpparam type="header" name="Content-Type" value="application/x-www-form-urlencoded">
        <cfhttpparam type="body" value="status=#oauthStruct.status#">
    </cfhttp>

如果我没有 Authorization 标头参数,我最终会收到 400 Bad Request 错误。您将所有必要的 OAuth 参数(包括您的数字签名)放在逗号分隔的列表中,如上所示,指明您的内容类型,最重要的是,您在 cfhttp 调用的正文参数中提供作为 URL 查询字符串的剩余变量.

于 2012-11-15T22:35:25.103 回答