Twitter,oauth和coldfusion [英] Twitter, oauth and coldfusion
本文介绍了Twitter,oauth和coldfusion的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想要发布到Twitter。我有应用程序已经验证,现在想发布更新。
这是我的http文章所在的位置:
cfhttp url =http://api.twitter.com/1/statuses/update.jsonmethod =post>
< cfhttpparam type =headername =statusvalue =#urlEncodedFormat('my test post')#/>
< cfhttpparam type =headername =oauth_consumer_keyvalue =xxx/>
< cfhttpparam type =headername =oauth_noncevalue =xxx/>
< cfhttpparam type =headername =oauth_signature_methodvalue =#urlEncodedFormat('HMAC-SHA1')#/>
< cfhttpparam type =headername =oauth_tokenvalue =xxx/>
< cfhttpparam type =headername =oauth_timestampvalue =#GetTickCount()#/>
< cfhttpparam type =headername =oauth_versionvalue =1.0/>
< / cfhttp>
有没有人这样做?
$ b
http://dev.twitter.com/pages/auth#auth-request
您需要构建签名基本字符串并发布为正文(警告:未测试的代码,CF8 +)
< cffunction name =makeSignatureBaseStringreturntype =stringoutput =false>
< cfargument name =httpMethodtype =stringrequired =true>
< cfargument name =baseUritype =stringrequired =true>
< cfargument name =valuestype =structrequired =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.jsonmethod =POST>
< cfloop collection =#params#item =key>
< cfheader type =headername =#key#value =#params [key]#>
< / cfloop>
<!--- add status to the params for makeSignatureBaseString()--->
< cfset params.status =设置我的twitter私のさえずりを设定する>
< cfhttpparam type =body
value =#makeSignatureBaseString('POST','http://api.twitter.com/1/statuses/update.json', params)#>
< / cfhttp>
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:
<cfhttp url="http://api.twitter.com/1/statuses/update.json" method="post">
<cfhttpparam type="header" name="status" value="#urlEncodedFormat('my test post')#" />
<cfhttpparam type="header" name="oauth_consumer_key" value="xxx" />
<cfhttpparam type="header" name="oauth_nonce" value="xxx" />
<cfhttpparam type="header" name="oauth_signature_method" value="#urlEncodedFormat('HMAC-SHA1')#" />
<cfhttpparam type="header" name="oauth_token" value="xxx" />
<cfhttpparam type="header" name="oauth_timestamp" value="#GetTickCount()#" />
<cfhttpparam type="header" name="oauth_version" value="1.0" />
</cfhttp>
Has anyone done this? Am I going down the right route?
解决方案
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>
这篇关于Twitter,oauth和coldfusion的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文