我正在尝试使用Yoda speak api。这是我的小提琴:
-
http://jsfiddle.net/Dansker/tdhnmmye/
$.ajax({ url: 'https://yoda.p.mashape.com/yoda', // The URL to the API. You can get this by clicking on "Show CURL example" from an API profile type: 'GET', // The HTTP Method data: {sentence: $("#boxArea").val()}, // Additional parameters here datatype: 'json', success: function (data) { alert(data); }, error: function (err) { alert(err); }, beforeSend: function (xhr) { xhr.setRequestHeader("X-Mashape-Authorization", "<RvyROurVRvmshRzDcAtXABdytvkDp1MtroWjsnXo8Dcs9Dq6SB>"); // Enter here your Mashape key } });});});
我认为代码都能工作,但我一直收到403个错误,说我的密钥不工作。我一直在重置我的钥匙,但它一直说它不起作用。是钥匙还是别的东西?"yoda speak"也将显示为警报?
只是猜测,但你试过去掉外尖括号吗?
尝试更改:
xhr.setRequestHeader("X-Mashape-Authorization", "<RvyROurVRvmshRzDcAtXABdytvkDp1MtroWjsnXo8Dcs9Dq6SB>");
对此:
xhr.setRequestHeader("X-Mashape-Authorization", "RvyROurVRvmshRzDcAtXABdytvkDp1MtroWjsnXo8Dcs9Dq6SB");