我有一个arduino上传传感器数据到cosm.com。我在本地Web服务器上创建了一个简单的网页,以查询cosm.com API并打印出值。JSONP传递api密钥
问题是,如果我没有在另一个选项卡中登录到cosm.com,我会看到这个弹出窗口。
的解决方案是我的公共密钥传递给cosm.com,但我在一路过来我这里头。
文档给出了如何做到这一点的卷曲的例子,但不是JavaScript的
curl --request GET --header "X-ApiKey: -Ux_JTwgP-8pje981acMa5811-mSAKxpR3VRUHRFQ3RBUT0g" https://api.cosm.com/v2/feeds/120687/datastreams/sensor_reading
我如何通过我的钥匙插入网址?:
function getJson() {
$.ajax({
type:'GET',
url:"https://api.cosm.com/v2/feeds/120687/datastreams/sensor_reading",
//This line isn't working
data:"X-ApiKey: -Ux_JTwgP-8pje981acMa5811-mSAKxpR3VRUHRFQ3RBUT0g",
success:function(feed) {
var currentSensorValue = feed.current_value;
$('#rawData').html(currentSensorValue);
},
dataType:'jsonp'
});
}
更新: 它必须是可能的因为hurl.it能够查询的API http://www.hurl.it/hurls/75502ac851ebc7e195aa26c62718f58fecc4a341/47ad3b36639001c3a663e716ccdf3840352645f1
更新2: 虽然我从来没有得到这个工作,我没有找到周围工作。 Cosm拥有自己的JavaScript库,可以满足我的需求。
http://cosm.github.com/cosm-js/ http://jsfiddle.net/spuder/nvxQ2/5/
谢谢!这就是我最终做的。 https://github.com/spudstud/Foosball – spuder