我有一個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