2011-04-06 16 views
3

我試圖獲得使用ColdFusion 9 Ning網絡憑證無效,所以首先這是捲曲語法測試API:ColdFusion的,該oauth_signature是

curl -k https://external.ningapis.com/xn/rest/mbdevsite/1.0/Token?xn_pretty=true -u [email protected]: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="[email protected]" 
     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"} 

確實有人知道可能是這個錯誤嗎?

網址和登錄信息是真實的,誰想要通過測試

幫助謝謝。

回答

2

不要在公開論壇上透露您的用戶名密碼&。 &密碼本已發行:)

你oauth_signature是36da2ea8-10fb-48CC-aaa4-c17c551c6b87 &不是 「36da2ea8-10fb-48CC-aaa4-c17c551c6b87 %26

我以後更好地更改此用戶名得到了成功的迴應&它正在完美運作。

<cfhttp 
      method="post" 
      url="https://external.ningapis.com/xn/rest/mbdevsite/1.0/Token" 
      username="[email protected]" 
      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> 
+0

感謝CF Mitrah的憑據,但是您是如何生成這個oauth_signature的? – Houssem 2011-04-10 21:48:10

+0

您提到的API響應**「oauth_signature無效」**。以及您的內容類型的API調用是「application/x-www-form-urlencoded」。所以我只需在你的oAuth簽名上運行url解碼函數# #urlDecode('36da2ea8-10fb-48cc-aaa4-c17c551c6b87%26')#' – 2011-04-11 06:02:49

0

你可以看看本納德爾的博客post on OAuth。他涵蓋了你可能遇到的一些事情。

1

爲什麼你使用cURL而不是cfhttp的具體原因是什麼? RIAForge上有一個不錯的庫: OAuth 這將幫助你處理OAuth。這個問題可能與參數編碼有關。

噢 - 你不應該發佈你的OAuth憑證。


UPDATE:

恐怕使用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"/> 

當然還有很多失蹤之前和之後的位。

+0

他在顯示cURL作品,而使用cfhttp的'相同'調用沒有。 – Henry 2011-04-06 17:24:39

+0

我也試過RIAForge庫,我也有同樣的迴應,我使用cURL的原因僅僅是爲了測試,並且關於網絡也用於測試 – Houssem 2011-04-06 18:54:41