Youtube api sencha touch 2中的youtube api v3 CORS支持
使用Sencha Touch,我们如何查询youtube v3搜索api? 下面是一个示例url,直接从浏览器发布时效果良好(注意:键是必需的): “” 但是,当使用sencha touch Store ajax代理加载时,相同的url会失败。 似乎对该URL进行了Youtube api sencha touch 2中的youtube api v3 CORS支持,youtube-api,sencha-touch,sencha-touch-2,youtube-javascript-api,Youtube Api,Sencha Touch,Sencha Touch 2,Youtube Javascript Api,使用Sencha Touch,我们如何查询youtube v3搜索api? 下面是一个示例url,直接从浏览器发布时效果良好(注意:键是必需的): “” 但是,当使用sencha touch Store ajax代理加载时,相同的url会失败。 似乎对该URL进行了OPTIONS调用,并且GET被中止 Sencha touch store中使用youtube V3谷歌API需要什么?我没有找到对youtube V3 api的jsonp支持。我曾经这样使用过这个api proxy: {
OPTIONS
调用,并且GET
被中止
Sencha touch store中使用youtube V3谷歌API需要什么?我没有找到对youtube V3 api的jsonp支持。我曾经这样使用过这个api
proxy: {
type: 'ajax',
url: 'https://www.googleapis.com/youtube/v3/search',
useDefaultXhrHeader: false,
extraParams: {
part: 'snippet',
q: 'ambarsariya',
regionCode: 'IN',
maxResults: 30,
key: 'your_key'
},
reader: {
type: 'json',
rootProperty: 'items'
}
}
你还需要做的一件事就是在这个商店的模型中设置了一个idProperty。我使用的模型的内部配置
idProperty: 'videoId',// its better if this name is not same as any fields name
fields: [{
name: 'snippet'
}, {
name: 'thumbnail',
mapping: 'snippet.thumbnails.default.url'
}, {
name: 'title',
mapping: 'snippet.title'
}]
希望这能解决您的问题。我使用过这样的api
proxy: {
type: 'ajax',
url: 'https://www.googleapis.com/youtube/v3/search',
useDefaultXhrHeader: false,
extraParams: {
part: 'snippet',
q: 'ambarsariya',
regionCode: 'IN',
maxResults: 30,
key: 'your_key'
},
reader: {
type: 'json',
rootProperty: 'items'
}
}
你还需要做的一件事就是在这个商店的模型中设置了一个idProperty。我使用的模型的内部配置
idProperty: 'videoId',// its better if this name is not same as any fields name
fields: [{
name: 'snippet'
}, {
name: 'thumbnail',
mapping: 'snippet.thumbnails.default.url'
}, {
name: 'title',
mapping: 'snippet.title'
}]
希望这能解决您的问题。对我来说效果很好
商店:-
Ext.define('MyApp.store.videos', {
extend: 'Ext.data.Store',
model: 'MyApp.model.Video',
config: {
autoLoad: true,
proxy: {
type: 'ajax',
//This is required to enable cross-domain request
useDefaultXhrHeader: false,
url: 'https://www.googleapis.com/youtube/v3/search',
extraParams: {
part: 'snippet',
q: "Enrique", //Query string
regionCode: 'IN',
maxResults: 30,
key: 'AIzaSyD6FvoLaIFqyQGoEY4oV7TEWGAJSlDd1-8'
}
}
}
});
This is the model used by the above store.
MyApp.model.Video:-
Ext.define('MyApp.model.Video', {
extend: 'Ext.data.Model',
requires: [],
config: {
idProperty: 'videoId',
fields: [{
name: 'id'
}, {
name: 'videoId',
mapping: 'id.videoId'
}]
}
});
它也适用于jsonp代理
只需在代理中更改类型:jsonp并删除useDefaultXhrHeader配置。它对我很有效
商店:-
Ext.define('MyApp.store.videos', {
extend: 'Ext.data.Store',
model: 'MyApp.model.Video',
config: {
autoLoad: true,
proxy: {
type: 'ajax',
//This is required to enable cross-domain request
useDefaultXhrHeader: false,
url: 'https://www.googleapis.com/youtube/v3/search',
extraParams: {
part: 'snippet',
q: "Enrique", //Query string
regionCode: 'IN',
maxResults: 30,
key: 'AIzaSyD6FvoLaIFqyQGoEY4oV7TEWGAJSlDd1-8'
}
}
}
});
This is the model used by the above store.
MyApp.model.Video:-
Ext.define('MyApp.model.Video', {
extend: 'Ext.data.Model',
requires: [],
config: {
idProperty: 'videoId',
fields: [{
name: 'id'
}, {
name: 'videoId',
mapping: 'id.videoId'
}]
}
});
它也适用于jsonp代理
只需在代理中更改类型:jsonp并删除useDefaultXhrHeader配置。Thnx
useDefaultXhrHeader:false
在我的案例中丢失。ThnxuseDefaultXhrHeader:false在我的案例中丢失了
。