Twitter, oauth and coldfusion

前端 未结 1 2010
误落风尘
误落风尘 2020-12-19 09:26

I am trying to post to twitter. I have the app already authenticated and now want to post an update.

This is what my http post is at:



        
相关标签:
1条回答
  • 2020-12-19 09:59

    have you read this?

    http://dev.twitter.com/pages/auth#auth-request

    you need to construct the "signature base string" and post as body (warning: untested code, for CF8+)

    <cffunction name="makeSignatureBaseString" returntype="string" output="false">
      <cfargument name="httpMethod" type="string" required="true">
      <cfargument name="baseUri" type="string" required="true">
      <cfargument name="values" type="struct" required="true">
    
      <cfset var signatureBaseString = "#httpMethod#&#URLEncodedFormat(baseUri)#&">
      <cfset var keys = StructKeyArray(values)>
      <cfset var key = "">
    
      <cfset ArraySort(keys, "textNoCase")>
      <cfloop array="#keys#" index="key">
        <cfset signatureBaseString &= URLEncodedFormat("&#key#=#values[key]#")>
      </cfloop>
    
      <cfreturn signatureBaseString>
    </cffunction>
    

    -

    <!--- using values from http://dev.twitter.com/pages/auth#auth-request --->
    <cfset params = {
      oauth_consumer_key = "GDdmIQH6jhtmLUypg82gる",
      oauth_nonce = "oElnnMTQIZvqvlfXM56aBLAf5noGD0AQR3Fmi7Q6Y",
      oauth_signature_method = "HMAC-SHA1",
      oauth_token = "819797-Jxq8aYUDRmykzVKrgoLhXSq67TEa5ruc4GJC2rWimw",
      oauth_timestamp = "1272325550",
      oauth_version = "1.0"
    }>
    
    <cfhttp url="http://api.twitter.com/1/statuses/update.json" method="POST">
     <cfloop collection="#params#" item="key">
       <cfheader type="header" name="#key#" value="#params[key]#">
     </cfloop>
    
     <!--- add status to the params for makeSignatureBaseString() --->
     <cfset params.status = "setting up my twitter 私のさえずりを設定する">
    
     <cfhttpparam type="body"
       value="#makeSignatureBaseString('POST', 'http://api.twitter.com/1/statuses/update.json', params)#">
    </cfhttp>
    
    0 讨论(0)
提交回复
热议问题