【问题标题】:Issue in generating oauth_signature for twitter in coldfusion在coldfusion中为twitter生成oauth_signature的问题
【发布时间】:2020-03-15 18:54:54
【问题描述】:

我在创建 OAuth 签名时开始了 twitter API 测试,显示的响应是

{"errors":[{"code":215,"message":"Bad Authentication data."}]}

添加了文档中提到的所有参数和标题,但没有得到正确的结果,如果我做错了什么,请告诉我。

<cfset status = "Hello Ladies + Gentlemen, a signed OAuth">
<cfset include_entities = true >
<cfset oauth_consumer_key = "x3OgJNjJ5TPGj7jyvLz9rUzfU">
<cfset oauth_nonce = createUUID()>
<cfset oauth_signature_method ="HMAC-SHA1" >
<cfset oauth_timestamp   = GetTickCount()/1000>
<cfset oauth_token   = "1196333045885702145-BPWGfPyKakezuqYoLaYXiIgQ5TWAkf">
<cfset oauth_version   = "1.0">

<cfset parameterString = "include_entities=true&oauth_consumer_key=#oauth_consumer_key#&oauth_nonce=#oauth_nonce#&oauth_signature_method=#oauth_signature_method#&oauth_timestamp=#oauth_timestamp#&oauth_token=#oauth_token#&oauth_version=1.0&status=#urlEncodedFormat(status)#" >
<cfdump var="#parameterString#">

<cfhttp url="https://api.twitter.com/1.1/statuses/update.json" method="POST" >
  <cfhttpparam type="header" name="Content-Type" value="application/x-www-form-urlencoded">
  <cfhttpparam type="header" name="mimetype" value="application/x-www-form-urlencoded" />
  <cfhttpparam type="header" name="Accept" value="*/*" />
  <cfhttpparam type="header" name="Connection" value="close" />
  <cfhttpparam type="header" name="Host" value="api.twitter.com" />
  <cfhttpparam type="header" name="User-Agent" value="OAuth gem v0.4.4" />

  <cfhttpparam type="header" name="Content-Length" value="76">
  <cfhttpparam type="header" name="include_entities" value="#include_entities#">
  <cfhttpparam type="header" name="oauth_consumer_key" value="#oauth_consumer_key# ">
  <cfhttpparam type="header" name="oauth_nonce" value="#oauth_nonce#">
  <cfhttpparam type="header" name="oauth_signature_method" value="#oauth_signature_method#">
  <cfhttpparam type="header" name="oauth_timestamp" value="#oauth_timestamp#">
  <cfhttpparam type="header" name="oauth_token" value="#oauth_token#">
  <cfhttpparam type="header" name="oauth_version" value="#oauth_version#">
  <cfhttpparam type="header" name="status" value="#urlEncodedFormat(status)#">

 <cfhttpparam type="body" value="#parameterString#"   >
</cfhttp>
<cfdump var="#cfhttp#"><cfabort>

【问题讨论】:

标签: api twitter coldfusion twitter-oauth


【解决方案1】:

参考这个并在 twitter 上创建你的开发者帐户,通过你自己的密钥,ouath 将起作用。参考这个create secret key for oauth

【讨论】:

    【解决方案2】:

    使用此方法,它会正常工作

    <cfset consumerKey = "xxxxxxxxxxxxxx">
        <cfset consumerSecret = "xxxxxxxxxxxxxxxxxxx">
        <cfset bearerToken = ToBase64(consumerKey & ":" & consumerSecret)>
        <cfset authorization = "Basic " & bearerToken>
        <cfhttp url="https://api.twitter.com/oauth2/token" method="post" charset="utf-8" >
            <cfhttpparam type="header" name="Authorization" value="#authorization#">
            <cfhttpparam type="header" name="Content-Type" value="application/x-www-form-urlencoded;charset=UTF-8">
            <cfhttpparam type="body" value="grant_type=client_credentials">
        </cfhttp>
    

    【讨论】:

    猜你喜欢
    • 2011-11-27
    • 2011-08-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-08
    • 1970-01-01
    相关资源
    最近更新 更多