我正在尝试使用Coldfusion 9从ning network获取凭据,所以首先使用curl语法来测试api:
curl -k https://external.ningapis.com/xn/rest/mbdevsite/1.0/Token?xn_pretty=true -u devshare@megabase.tn:mbdev2011 -d "oauth_signature_method=PLAINTEXT&
oauth_consumer_key=741ab68b-63fb-4949-891c-9e88f5143034&oauth_signature=36da2ea8
-10fb-48cc-aaa4-c17c551c6b87%26"然后返回:
{
"success" : true,
"entry" : {
"author" : "1o0butfek0b3p",
"oauthConsumerKey" : "741ab68b-63fb-4949-891c-9e88f5143034",
"oauthToken" : "46f1e137-549a-4d9d-ae05-62782debfd3d",
"oauthTokenSecret" : "9f778ab5-db8e-4f3e-b17f-61d249b91f0a"
},
"resources" : {
}然后我将其转换为coldfusion,如下所示:
<cfhttp
method="post"
url="https://external.ningapis.com/xn/rest/mbdevsite/1.0/Token"
username="devshare@megabase.tn"
password="mbdev2011">
<cfhttpparam type="header" name="content-type" value="application/x-www-form-urlencoded">
<cfhttpparam name="oauth_signature_method" type="FormField" value="PLAINTEXT"/>
<cfhttpparam name="oauth_consumer_key" type="FormField" value="741ab68b-63fb-4949-891c-9e88f5143034"/>
<cfhttpparam name="oauth_signature" type="FormField" value="36da2ea8-10fb-48cc-aaa4-c17c551c6b87%26"/>
</cfhttp>
<cfoutput>
#cfhttp.fileContent#
</cfoutput> 得到的回应总是:
{"success":false,"reason":"The oauth_signature is invalid. That is, it doesn't match the signature computed by the Service Provider.","status":401,"code":1,"subcode":12,"trace":"3d874587-072b-4877-b27e-b84ee2e2b537"} 有人知道这可能是什么错误吗??
url和登录信息对于想要通过测试提供帮助的人来说是真实的
谢谢。。
发布于 2011-04-10 21:11:09
不要在公共论坛上泄露你的用户名和密码。最好在此问题完成后更改此用户名和密码:)
您的oauth_signature is 36da2ea8-10fb-48cc-aaa4-c17c551c6b87& not "36da2ea8-10fb-48cc-aaa4-c17c551c6b87%26“
我得到了成功的响应&它工作得很好。
<cfhttp
method="post"
url="https://external.ningapis.com/xn/rest/mbdevsite/1.0/Token"
username="devshare@megabase.tn"
password="mbdev2011">
<cfhttpparam type="header" name="content-type" value="application/x-www-form-urlencoded">
<cfhttpparam name="oauth_signature_method" type="FormField" value="PLAINTEXT"/>
<cfhttpparam name="oauth_consumer_key" type="FormField" value="741ab68b-63fb-4949-891c-9e88f5143034"/>
<cfhttpparam name="oauth_signature" type="FormField" value="36da2ea8-10fb-48cc-aaa4-c17c551c6b87&"/>
</cfhttp> 发布于 2011-04-07 00:03:22
你使用cURL而不是cfhttp有什么特别的原因吗?在RIAForge上有一个很好的库: OAuth,它将帮助您处理OAuth。问题可能与参数编码有关。
哦--你不应该张贴你的OAuth凭证。
更新:
我担心使用OAuth并不像调用带参数的cfhttp那么简单。参数需要有一定的顺序,您需要使用适当的方法(在您的情况下是纯文本)对整个请求进行签名。签名过程还包括时间戳,因此您不能使用示例中的值测试代码,因为它们肯定不会工作。
如果你下载RIAForge库,那里有一个"\examples_external“文件夹和twitter.cfm -你会找到我在那里提到的所有东西。
下面是一些代码来说明我的意思:
<!--- Create empty token --->
<cfset oReq = CreateObject("component", "oauth.oauthrequest").fromConsumerAndToken(
oConsumer = oConsumer,
oToken = oToken,
sHttpMethod = "GET",
sHttpURL = sTokenEndpoint,stparameters= Parameters )>
<!--- Sign the request --->
<cfset oReq.signRequest(
oSignatureMethod = oReqSigMethodSHA,
oConsumer = oConsumer,
oToken = oToken)>
<!--- Get the request token --->
<cfhttp url="#oREQ.getString()#" method="get" result="tokenResponse"/>当然,在它之前和之后缺少了很多比特。
发布于 2011-04-06 23:37:02
你可以看看Ben Nadel的博客post on OAuth。他涵盖了你可能会遇到的一些事情。
https://stackoverflow.com/questions/5568425
复制相似问题