2016-07-14 23 views
1

我正試圖在我的Ruby on Rails應用程序中實現Adobe的Creative SDK。將高分辨率的Adobe Creative SDK從PHP轉換爲Ruby on Rails

https://creativesdk.adobe.com/docs/web/#/articles/highresolution/index.html

我有高分辨率的API所需的訪問。

他們的例子是PHP和Node.js,我正在嘗試編寫基於PHP的Ruby on Rails版本。我已經完成了所有設置,因爲它正確地調用了「authenticationURL」,但是我收到了「無效的authenticationURL響應,請檢查格式化響應。」

我是新手,在這個級別編程,基本上試圖通過參考PHP & Ruby這裏的幾個問題,以及像http://www.phptoruby.com/這樣的網站來解決這個問題。

這裏是PHP:

<!-- /getAuth --> 

<?php 
$apiKey = "apikey"; 
$apiSecret = "apisecret"; 
$salt = rand(0,1000); 
$time = time(); 
$sig = sha1($apiKey . $apiSecret . $time . $salt); 

$authObj = array(
    "apiKey" => $apiKey, 
    "salt" => $salt, 
    "timestamp" => $time, 
    "encryptionMethod" => 'sha1', 
    "signature" => $sig 
); 

echo json_encode($authObj); 

?> 

這是我目前所面對的(我apikey和apisecret正確輸入):

require 'time' 
require 'json' 
require 'digest/sha1' 

def get_auth 
apiKey = 'apikey' 
apiSecret = 'apisecret' 
salt = "#{0 + rand(1000)}" 
time = "#{Time.now.to_i}" 
sig = Digest::SHA1.hexdigest('apiKey' + 'apiSecret' + 'time' + 'salt') 


authObj = { :apiKey => 'apiKey', 
       :salt => 'salt', 
       :timestamp => 'time', 
       :encryptionMethod => 'sha1', 
       :signature => 'sig' } 

print 'authObj'.to_json 
render :fxb 
end 

我不知道,如果使用print是在這裏糾正?或者,如果我的問題是一個語法問題......或者完全是其他問題。

+0

問題解決了嗎?我也遇到了同樣的錯誤:「無效的authenticationURL響應,請檢查格式化響應。」我正在使用c#,並且我也可以訪問高分辨率API。向adobe提出投訴,但沒有人迴應。Auth對象是在C#中正確創建的gettin,我將json與auth對象的創意雲文檔測試url進行了比較,但仍然無法正常工作http://jsbin.com/xoxaqoropu/ – adang

+0

好的,我已經爲我解決了問題。在調試縮小的鳥舍js後,我發現我的getAuth函數返回了正確的json(auth),但我必須添加響應頭,以便鳥舍能夠將auth json對象解析爲簽名,時間戳。所以在返回json之前,我必須在getAuth方法中添加下面的代碼。沒有它,鳥舍正在讀取auth json作爲字符串,而不是對象,它沒有解析它。 Response.Clear(); Response.ContentType =「application/json; charset = utf-8」; – adang

回答

1

嘗試改變

sig = Digest::SHA1.hexdigest('apiKey' + 'apiSecret' + 'time' + 'salt') 

sig = Digest::SHA1.hexdigest(apiKey + apiSecret + time + salt) 

用單引號,它正在apiKey字符串本身的價值被散列,而不是它的價值。

而且,下面的需要被改變,以及以除去單引號:

authObj = { :apiKey => 'apiKey', 
       :salt => 'salt', 
       :timestamp => 'time', 
       :encryptionMethod => 'sha1', 
       :signature => 'sig' } 

print 'authObj'.to_json 

authObj = { :apiKey => apiKey, 
       :salt => salt, 
       :timestamp => time, 
       :encryptionMethod => sha1, 
       :signature => sig } 

print authObj.to_json 
+0

太棒了。現在我得到'NameError(未定義的局部變量或方法'sha1'爲#): app/controllers/uploads_controller.rb:28:'get_auth'' – mdh1

+0

我改變了':encryptionMethod => sha1'到':encryptionMethod =>'sha1'',我不再在日誌中獲得NameError,事實上,在日誌中一切似乎都沒問題 - salt,timestamp,signature和encryptionMethod (作爲'sha1')都在那裏,但現在我得到了初始的「無效authenticationURL響應」JavaScript錯誤再次。 – mdh1

0

添加爲控制器動作:

def auth_aviary 
    timestamp = Time.now.to_i.to_s 
    salt = rand(1000).to_s 
    sig = Digest::SHA1.hexdigest(
      Conf.aviary_api_key + 
      Conf.aviary_api_secret + 
      timestamp + 
      salt 
     ) 
    render json: { 
     "apiKey" => Conf.aviary_api_key, 
     "salt" => salt, 
     "timestamp" => timestamp, 
     "encryptionMethod" => 'sha1', 
     "signature" => sig 
    } 
    end 
0

響應爲那些仍然面臨問題的人提供一箇舊的職位。該解決方案可能會工作(至少爲asp.net)。我得到相同的錯誤,並且一旦我將響應內容類型設置爲「application/json; charset = utf-8」,就解決了它。沒有它,鳥舍正在讀AUTH JSON字符串作爲和不反對,它是無法解析爲時間戳,簽名等

Response.ContentType = "application/json; charset=utf-8"; 

希望這將有助於。

0

是在PHP我設置標題,一切正常。

header('Content-Type:application/json');

相關問題