404 当消耗黑暗天空天气 API 和 Ember
404 When Consuming Dark Sky Weather API with Ember
知道为什么当我尝试向 Dark Sky 发出 GET 请求时收到 404 吗? https://darksky.net/dev/docs
错误:
jquery.js:9600 GET https://api.darksky.net/forecast?key=secretString&latitude=42.361145&longitude=-71.057083&time=1525213510 404 (Not Found)
这是我的模型:
import DS from 'ember-data';
export default DS.Model.extend({
temperature: ('number'),
summary: DS.attr('string'),
icon: DS.attr('string')
});
这是我的路线(我也尝试以字符串格式保留纬度和经度):
import Route from '@ember/routing/route';
export default Route.extend({
model () {
let currentTime = Math.round(new Date()/1000);
return this.store.query('weather', { key: "secret_string", latitude: 42.361145, longitude: -71.057083, time: currentTime} );
}
});
这是我的适配器:
import DS from 'ember-data';
export default DS.RESTAdapter.extend({
host: "https://api.darksky.net",
pathForType() {
return 'forecast';
}
});
这是我的序列化程序:
import DS from 'ember-data';
export default DS.RESTSerializer.extend({
normalizeResponse(store, primaryModelClass, payload, id, requestType) {
payload = { weather: payload };
return this._super(store, primaryModelClass, payload, id, requestType);
}
});
您的 GET 请求不符合 Dark Sky 文档中的格式,复制粘贴如下:
https://api.darksky.net/forecast/0123456789abcdef9876543210fedcba/42.3601,-71.0589
您的请求将键作为查询参数而不是 URL 段。
您可以在适配器中指定主机或命名空间,使密钥成为 url 段:
import DS from 'ember-data';
export default DS.RESTAdapter.extend({
host: "https://api.darksky.net/yoursecretkey",
});
知道为什么当我尝试向 Dark Sky 发出 GET 请求时收到 404 吗? https://darksky.net/dev/docs
错误:
jquery.js:9600 GET https://api.darksky.net/forecast?key=secretString&latitude=42.361145&longitude=-71.057083&time=1525213510 404 (Not Found)
这是我的模型:
import DS from 'ember-data';
export default DS.Model.extend({
temperature: ('number'),
summary: DS.attr('string'),
icon: DS.attr('string')
});
这是我的路线(我也尝试以字符串格式保留纬度和经度):
import Route from '@ember/routing/route';
export default Route.extend({
model () {
let currentTime = Math.round(new Date()/1000);
return this.store.query('weather', { key: "secret_string", latitude: 42.361145, longitude: -71.057083, time: currentTime} );
}
});
这是我的适配器:
import DS from 'ember-data';
export default DS.RESTAdapter.extend({
host: "https://api.darksky.net",
pathForType() {
return 'forecast';
}
});
这是我的序列化程序:
import DS from 'ember-data';
export default DS.RESTSerializer.extend({
normalizeResponse(store, primaryModelClass, payload, id, requestType) {
payload = { weather: payload };
return this._super(store, primaryModelClass, payload, id, requestType);
}
});
您的 GET 请求不符合 Dark Sky 文档中的格式,复制粘贴如下:
https://api.darksky.net/forecast/0123456789abcdef9876543210fedcba/42.3601,-71.0589
您的请求将键作为查询参数而不是 URL 段。
您可以在适配器中指定主机或命名空间,使密钥成为 url 段:
import DS from 'ember-data';
export default DS.RESTAdapter.extend({
host: "https://api.darksky.net/yoursecretkey",
});