Javascript 将高分辨率Adobe Creative SDK从PHP转换为Ruby on Rails
我正在尝试将Adobe的CreativeSDK实现到我的RubyonRails应用程序中 我有必要访问hi-res API 他们的例子是针对PHP和Node.js的,我正在尝试基于PHP编写RubyonRails版本。我已经全部设置好了,因为它正确地调用了“authenticationURL”,但我得到了一个“无效的authenticationURL响应。请检查响应的格式。” 我对这个级别的编程还不熟悉,基本上是通过在这里参考一些关于PHP和Ruby的问题以及类似的网站来解决这个问题的 以下是PHP:Javascript 将高分辨率Adobe Creative SDK从PHP转换为Ruby on Rails,javascript,php,ruby-on-rails,adobecreativesdk,Javascript,Php,Ruby On Rails,Adobecreativesdk,我正在尝试将Adobe的CreativeSDK实现到我的RubyonRails应用程序中 我有必要访问hi-res API 他们的例子是针对PHP和Node.js的,我正在尝试基于PHP编写RubyonRails版本。我已经全部设置好了,因为它正确地调用了“authenticationURL”,但我得到了一个“无效的authenticationURL响应。请检查响应的格式。” 我对这个级别的编程还不熟悉,基本上是通过在这里参考一些关于PHP和Ruby的问题以及类似的网站来解决这个问题的 以下是
<!-- /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);
?>
我不确定在这里使用print
是否正确?或者如果我的问题是语法问题。。。或者完全其他的东西。试着改变一下
sig = Digest::SHA1.hexdigest('apiKey' + 'apiSecret' + 'time' + 'salt')
到
使用单引号,它将apiKey
字符串本身作为要散列的值,而不是其值
此外,还需要更改以下内容以删除单引号:
authObj = { :apiKey => 'apiKey',
:salt => 'salt',
:timestamp => 'time',
:encryptionMethod => 'sha1',
:signature => 'sig' }
print 'authObj'.to_json
到
将此添加为控制器操作:
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
回复那些仍然面临问题的人的旧帖子。该解决方案可能有效(至少适用于asp.net)。我遇到了同样的错误,当我将响应内容类型设置为“application/json;charset=utf-8”时,它就被解决了。没有它,aviary将auth json作为字符串而不是对象读取,并且无法将其解析为时间戳、签名等
Response.ContentType = "application/json; charset=utf-8";
希望它能有所帮助。是的,在php中,我设置了标题,一切都很好
标题('Content-Type:application/json') 太棒了。不再得到那个错误,但现在我得到了
namererror(未定义的局部变量或方法'sha1'):app/controllers/uploads\u controller.rb:28:in'get\u auth'
我将:encryptionMethod=>sha1
改为:encryptionMethod=>'sha1'
,我不再在日志中得到namererror
,事实上,日志中的一切似乎都正常-salt、timestamp、signature和encryptionMethod(如'sha1')都在,但现在我又遇到了初始的“Invalid authenticationURL response”javascript错误。您的问题解决了吗?我还收到与“无效的authenticationURL响应。请检查响应的格式”相同的错误。我使用的是c#,我还可以访问高分辨率API。向adobe提出投诉,但无人回应。Auth对象在C#中正确创建,我已经将json与Auth对象的creative cloud文档测试url进行了比较,但仍然无法正常工作,我已经为自己解决了这个问题。调试缩小的aviary js后,我发现我的getAuth函数返回了正确的json(auth),但我必须添加响应头,以便aviary可以将auth json对象解析为签名,即时间戳。因此,在返回json之前,我必须在getAuth方法中添加以下内容。没有它,aviary将auth json作为字符串而不是对象读取,并且无法解析它。Response.Clear();Response.ContentType=“application/json;charset=utf-8”;
authObj = { :apiKey => apiKey,
:salt => salt,
:timestamp => time,
:encryptionMethod => sha1,
:signature => sig }
print authObj.to_json
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
Response.ContentType = "application/json; charset=utf-8";